Instant hashCode() method in Java with Examples

The hashCode() method of Instant Class is used to get hashCode for this Instant. 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()

Returns: This method returns the hashCode for this Instant.

Below programs illustrate the Instant.hashCode() method:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// Instant.hashCode() method
  
import java.time.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create a Instant object
        Instant instant
            = Instant.parse("2018-12-30T19:34:50.63Z");
  
        // get hashCode
        // using hashCode()
        int value = instant.hashCode();
  
        // print result
        System.out.println("hashCode value: "
                           + value);
    }
}

chevron_right


Output:

hashCode value: -683539878

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate
// Instant.hashCode() method
  
import java.time.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create a Instant object
        Instant instant = Instant.now();
  
        // current Instant
        System.out.println("Current Instant: "
                           + instant);
  
        // get hashCode
        // using hashCode()
        int value = instant.hashCode();
  
        // print result
        System.out.println("hashCode value: "
                           + value);
    }
}

chevron_right


Output:

Current Instant: 2018-11-27T04:45:52.428Z
hashCode value: 1896457472

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



My Personal Notes arrow_drop_up

I am a Developer I love to code and bring my ideas alive

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.