w3resource logo

:

Java Programming Exercies

Java String Exercises: Create a unique identifier of a given string

Java String : Exercise-18 with Solution

Write a Java program to create a unique identifier of a given string.

Sample Solution:

Java Code:

public class Exercise18 {
 
  public static void main(String[] args)
    {
        String str = "Python Exercises.";

        // Get the hash code for the above string.
        int hash_code = str.hashCode();

        // Display the hash code.
        System.out.println("The hash for " + str +
            " is " + hash_code);
    }
}

Sample Output:

The hash for Python Exercises. is 863132599 

Java Practice online:

Improve this sample solution and post your code through Disqus