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 paramters.
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 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 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–
Recommended Posts:
- Calendar get() method in Java with Examples
- Calendar set() Method in Java with Examples
- Calendar add() Method in Java with Examples
- Calendar getActualMaximum() Method in Java with Examples
- Calendar getInstance() Method in Java with Examples
- Calendar getGreatestMinimum() Method in Java with Examples
- Calendar getActualMinimum() Method in Java with Examples
- Calendar getTimeZone() Method in Java with Examples
- Calendar setFirstDayOfWeek() Method in Java with Examples
- Calendar setLenient() Method in Java with Examples
- Calendar getMaximum() method in Java with Examples
- Calendar getLeastMaximum() method in Java with Examples
- Calendar internalGet() Method in Java with Examples
- Calendar toString() Method in Java with Examples
- Calendar getFirstDayOfWeek() 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.



