w3resource logo


Java Programming Exercies

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

Secondary Nav

Java String : Exercise-18 with Solution

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

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);
    }
}

Output:

The hash for Python Exercises. is 863132599

Java Practice online:

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);
    }
}



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program