Java Utility Library

Java Calendar - hashCode() Method



The java.util.Calendar.hashCode() method returns a hash code for this calendar.

Syntax

public int hashCode()

Parameters

No parameter is required.

Return Value

Returns a hash code value for this object.

Exception

NA

Example:

In the example below, the java.util.Calendar.hashCode() method returns a hash code value for a given Calendar object.

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //creating a Calendar instance
    Calendar Cal = Calendar.getInstance();

    //Creating a date object from calendar and printing it
    System.out.println("The Calendar is: " + Cal.getTime());

    //Printing the hash code of the Calendar instance
    System.out.println("The hashCode is: " + Cal.hashCode());    
  }
}

The output of the above code will be:

The Calendar is: Sat May 08 10:31:08 UTC 2021
The hashCode is: 1267676783

❮ Java.util - Calendar