The hashCode() method of UUID class in Java is generally used to get the hash code value of the UUID.
Syntax:
public int hashCode()
Parameters: This method does not take any parameter.
Return Value: This method returns an integer value which is the hashCode value for this UUID instance.
Below programs illustrate the working of hashCode() method:
Program 1:
// Java code to illustrate hashCode() method import java.util.*; public class UUID_Demo { public static void main(String[] args) { // Creating two UUIDs UUID UUID_1 = UUID .fromString( "58e0a7d7-eebc-11d8-9669-0800200c9a66"); // Displaying the UUID System.out.println("UUID: " + UUID_1); // Displaying the hashCode value System.out.println("The hashCode value is: " + UUID_1.hashCode()); } } |
UUID: 58e0a7d7-eebc-11d8-9669-0800200c9a66 The hashCode value is: 3744873
Program 2:
// Java code to illustrate hashCode() method import java.util.*; public class UUID_Demo { public static void main(String[] args) { // Creating two UUIDs UUID UUID_1 = UUID .fromString( "5fc03087-d265-11e7-b8c6-83e29cd24f4c"); // Displaying the UUID System.out.println("UUID: " + UUID_1); // Displaying the hashCode Value System.out.println("The hashCode value is: " + UUID_1.hashCode()); } } |
UUID: 5fc03087-d265-11e7-b8c6-83e29cd24f4c The hashCode value is: -1447957042
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- UUID compareTo() Method in Java with Examples
- UUID getLeastSignificantBits() Method in Java with Examples
- UUID variant() Method in Java with Examples
- UUID version() Method in Java with Examples
- UUID nameUUIDFromBytes() Method in Java with Examples
- UUID fromString() Method in Java with Examples
- UUID clockSequence() Method in Java with Examples
- UUID getMostSignificantBits() Method in Java with Examples
- UUID equals() Method in Java with Examples
- UUID toString() Method in Java with Examples
- UUID timestamp() Method in Java with Examples
- UUID node() Method in Java with Examples
- Map hashCode() Method in Java with Examples
- Set hashCode() method in Java with Examples
- ChronoZonedDateTime hashCode() method in Java with Examples
- CompoundName hashCode() method in Java with Examples
- Byte hashCode() method in Java with examples
- List hashCode() Method in Java with Examples
- OffsetDateTime hashCode() method in Java with examples
- ZoneId hashCode() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

