The hashCode() method in Calendar class is used to return the hash code for this Calendar Object.
Syntax:
public int hashCode()
Parameters: The method does not take any parameters.
Return Value: The method returns the hash code value for this calendar object..
Below programs illustrate the working of hashCode() Method of Calendar class:
Example 1:
Java
// Java code to illustrate // hashCode() method import java.util.*; public class Calendar_Demo { public static void main(String args[]) { // Creating a calendar object Calendar calndr = Calendar.getInstance(); // Displaying the current calendar System.out.println( "The time on" + " Calendar shows: " + calndr.getTime()); // Getting the hash code int hash_code = calndr.hashCode(); System.out.println( "The hash code " + "for this calendar is: " + hash_code); } } |
The time on Calendar shows: Wed Feb 20 15:55:22 UTC 2019 The hash code for this calendar is: 194416203
Example 2:
Java
// Java code to illustrate // hashCode() method import java.util.*; public class Calendar_Demo { public static void main(String args[]) { // Creating a calendar Calendar calndr = new GregorianCalendar( 2018 , 6 , 10 ); // Displaying the current calendar System.out.println( "The time on" + " Calendar shows: " + calndr.getTime()); // Getting the hash code int hash_code = calndr.hashCode(); System.out.println( "The hash code " + "for this calendar is: " + hash_code); } } |
The time on Calendar shows: Tue Jul 10 00:00:00 UTC 2018 The hash code for this calendar is: -2123101761
Reference: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#hashCode–