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 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 nano second field using getNano() int hashcode = time.hashCode(); // print result System.out.println("hashCode: " + hashcode); } } |
hashCode: 2074672050
Program 2:
// 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 nano second field using getNano() int hashcode = time.hashCode(); // print result System.out.println("hashCode: " + hashcode); } } |
hashCode: -1466552081
Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#hashCode()
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
Recommended Posts:
- LocalTime toNanoOfDay() method in Java with Examples
- LocalTime toSecondOfDay() method in Java with Examples
- LocalTime isBefore() method in Java with Examples
- LocalTime isAfter() method in Java with Examples
- LocalTime get() method in Java with Examples
- LocalTime getLong() method in Java with Examples
- LocalTime getMinute() method in Java with Examples
- LocalTime getSecond() method in Java with Examples
- LocalTime getNano() method in Java with Examples
- LocalTime getHour() method in Java with Examples
- LocalTime from() method in Java with Examples
- LocalTime format() method in Java with Examples
- LocalTime equals() method in Java with Examples
- LocalTime compareTo() method in Java with Examples
- LocalTime adjustInto() method in Java with Examples
- LocalTime atDate() method in Java with Examples
- LocalTime atOffset() method in Java with Examples
- LocalTime ofNanoOfDay() method in Java with Examples
- LocalTime ofInstant() method in Java with Examples
- LocalTime ofSecondOfDay() 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.

