How to convert a String to an id or numeric data?

2

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.

    
asked by anonymous 11.02.2016 / 22:00

1 answer

4

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?

    
11.02.2016 / 22:13