I have strings that are unique and I would like to create an id from it.
Does anyone know how I can do it?
Thank you in advance.
I have strings that are unique and I would like to create an id from it.
Does anyone know how I can do it?
Thank you in advance.
The hashCode () of the String class turns the String representation into an integer.
Java example:
public static void main (String[] args) throws java.lang.Exception
{
String[] strings = {"abc","def","ggh","rrt"};
for(int i = 0; i < strings.length;i++)
System.out.println(strings[i].hashCode());
}
This code will print the following sequence:
96354 //abc
99333 //def
102280 //ggh
113204 //rrt
See working here .
Related question: Using hashcode as id is a good practice?