Saturday, March 14, 2026
HomeLanguagesJavaLocalTime hashCode() method in Java with Examples

LocalTime hashCode() method in Java with Examples

The hashCode() method of a LocalTime class is used to return hashCode for this time. The hashcode is always the same if the object doesn’t change. Hashcode is a unique code generated by the JVM at time of object creation. It can be used to perform some operation on hashing related algorithm like hashtable, hashmap etc. An object can also be searched with its unique code (hashcode). 

Syntax:

public int hashCode()

Parameters: This method does not accept any parameter. 

Return value: This method returns an integer value which is the hashCode. 

Below programs illustrate the hashCode() method: 

Program 1: 

Java




// Java program to demonstrate
// LocalTime.hashCode() method
 
import java.time.*;
 
public class GFG {
    public static void main(String[] args)
    {
        // create a LocalTime object
        LocalTime time
            = LocalTime.parse("10:44:59.73");
 
        // get hashcode using gethashCode() method
        int hashcode = time.hashCode();
 
        // print result
        System.out.println("hashCode: "
                           + hashcode);
    }
}


Output:

hashCode: 2074672050

Program 2: 

Java




// Java program to demonstrate
// LocalTime.hashCode() method
 
import java.time.*;
 
public class GFG {
    public static void main(String[] args)
    {
        // create a LocalTime object
        LocalTime time
            = LocalTime.parse("18:00:01");
 
        // get hashcode using gethashCode() method
        int hashcode = time.hashCode();
 
        // print result
        System.out.println("hashCode: "
                           + hashcode);
    }
}


Output:

hashCode: -1466552081

Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#hashCode()

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32506 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6882 POSTS0 COMMENTS
Nicole Veronica
12005 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12099 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6967 POSTS0 COMMENTS
Umr Jansen
6956 POSTS0 COMMENTS