int representation of a string

Hello experts,

I need to take a unique id which is a string and convert it into an integer. How can I do that and ensure the integer is also unique?

Cheers,
Matt.
mb2297Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
objectsConnect With a Mentor Commented:
return value from hashCode does not need to be unique.
you could just return the hashCode() of the concatenated string you have
0
 
objectsCommented:
String sid = "123";
int id = Integer.parseInt(sid);

unique according to what exactly?
0
 
mb2297Author Commented:
Sorry, I should have said the String is alphanumeric - parseInt will throw a NumberFormatException in that case.

I'm basically trying to override Object's hashCode() function.

Each of my objects is a row in a table, so they have a row identifier (an int) and a table identifier (a String). I want to concatenate the two together to form an id which can uniquely id any row in any table.

However, hashCode() requires that you return an int - so I need to parse that unique alphanumeric id into a unique integer id.

Hope that makes sense. I should have been more clear, sorry.

Thanks,
Matt.
0
 
mb2297Author Commented:
Hello again objects.

In the interest of HashMap efficiency, I would like the codes to be unique, and returning the code of the concatentated string works just fine.

Many thanks!
Matt.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.