Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8430211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:32:47+00:00 2026-06-10T05:32:47+00:00

Giving a Input String, the string length will not more than 30, the output

  • 0

Giving a Input String, the string length will not more than 30, the output will be a unique id number. Is there a way in Java can do this?the same string will always generate the same id, different string can not generate the same id. the java HashCode() can do this ?

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:32:49+00:00Added an answer on June 10, 2026 at 5:32 am

    To satisfy the requirement

    the same string will always generate the same id, different string can not generate the same id

    you’ll get pretty huge numbers. You require that the function will be injective so you need as many numbers as the number of possible Strings, which is something like $255^30$ in your case (or something like $65536^30$ if you allow arbitrary Unicode characters). So you’ll need BigIntegers for that and certainly you use int (simply there are more Strings of length up to 30 than numbers in int). For example, new BigInteger(theString.getBytes("")) satisfies your requirement.

    If you use hashCode, you’ll lose injectivity, but the chance that two Strings will have the same hashCode is very low in most cases (it’s actually the purpose of hashing to make this chance low). If you want to be extra sure that the number of collisions uniformly small, you can use some cryptographic hash function, but still, the mapping won’t be injective.

    Perhaps explaining the reasons for your requirements would help finding the best solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to dynamically create an object using a string as the
I have a JSON input which can go to any number of levels. I'm
I want to create a component by giving XML source input directly using core
Gradle is giving me fits. I have a build.gravle that includes the java plug-in
I am giving the form a dynamic number of file upload fields. So on
A have the following input string: string input = Ta005000000000000000000Tb001700000000000000000Sa005000000000000000000 + Sb002500000000000000000F 00000000000000000I 00000000000000000N
Consider the string 55,33,255,66,55 I am finding ways to count number of occurence of
If I have an input string and an array: s = to_be_or_not_to_be pos =
Actually I need to handle situation like I should be giving input as rows
I am giving input as int and according to that input I want combination

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.