LocalDateTime hashCode() method in Java with Examples
The hashCode() method of an LocalDateTime class is used to return a hash code for this LocalDateTime instance. The hashcode is always the same if the object doesn’t change. This method is derived from the Object class of Java and performs in a similar way.
Syntax:
public int hashCode()
Parameter: This method does not accept any parameter.
Returns: This method returns integer value which is the hashcode value for this LocalDateTime instance.
Below programs illustrate the LocalDateTime.hashCode() method:
Program 1:
// Java program to demonstrate // LocalDateTime.hashCode() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalDateTime Object LocalDateTime local = LocalDateTime.parse("2017-07-22T09:32:42"); // get hashcode for LocalDateTime int hascode = local.hashCode(); // print result System.out.println("hashCode value: " + hascode); } } |
hashCode value: -2030906730
Program 2:
// Java program to demonstrate // LocalDateTime.hashCode() method import java.time.*; public class GFG { public static void main(String[] args) { // create a LocalDateTime Object LocalDateTime local = LocalDateTime.parse("2006-01-02T19:32:42"); // get hashcode for LocalDateTime int hascode = local.hashCode(); // print result System.out.println("hashCode value: " + hascode); } } |
hashCode value: 1849330620
Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalDateTime.html#hashCode()
Recommended Posts:
- LocalDateTime until() Method in Java with Examples
- LocalDateTime with() Method in Java with Examples
- LocalDateTime now() Method in Java with Examples
- LocalDateTime plus() method in Java with Examples
- LocalDateTime from() method in Java with Examples
- LocalDateTime minus() method in Java with Examples
- LocalDateTime toLocalTime() method in Java with Examples
- LocalDateTime plusWeeks() method in Java with Examples
- LocalDateTime isEqual() method in Java with Examples
- LocalDateTime plusMinutes() method in Java with Examples
- LocalDateTime plusHours() method in Java with Examples
- LocalDateTime plusDays() method in Java with Examples
- LocalDateTime plusMonths() method in Java with Examples
- LocalDateTime plusNanos() method in Java with Examples
- LocalDateTime plusSeconds() 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.



