Calendar hashCode() Method in Java with Examples
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
import java.util.*;
public class Calendar_Demo {
public static void main(String args[])
{
Calendar calndr = Calendar.getInstance();
System.out.println( "The time on"
+ " Calendar shows: "
+ calndr.getTime());
int hash_code = calndr.hashCode();
System.out.println( "The hash code "
+ "for this calendar is: "
+ hash_code);
}
}
|
Output:
The time on Calendar shows: Wed Feb 20 15:55:22 UTC 2019
The hash code for this calendar is: 194416203
Example 2:
Java
import java.util.*;
public class Calendar_Demo {
public static void main(String args[])
{
Calendar calndr
= new GregorianCalendar( 2018 , 6 , 10 );
System.out.println( "The time on"
+ " Calendar shows: "
+ calndr.getTime());
int hash_code = calndr.hashCode();
System.out.println( "The hash code "
+ "for this calendar is: "
+ hash_code);
}
}
|
Output:
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–
Last Updated :
05 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...