Friday, May 8, 2026
HomeLanguagesJavaUUID hashCode() Method in Java with Examples

UUID hashCode() Method in Java with Examples

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


Output:

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


Output:

UUID: 5fc03087-d265-11e7-b8c6-83e29cd24f4c
The hashCode value is: -1447957042
RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6962 POSTS0 COMMENTS