Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

LocalDateTime hashCode() method in Java with Examples

  • Last Updated : 20 Nov, 2021

The hashCode() method of a 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: 

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

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




// 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 hashcode = local.hashCode();
 
        // print result
        System.out.println("hashCode value: "
                           + hashcode);
    }
}
Output: 
hashCode value: -2030906730

 

Program 2: 

Java




// 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);
    }
}
Output: 
hashCode value: 1849330620

 

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!