Java.util.Calendar类

java.util.Calendar.hashCode() 方法返回此日历的哈希代码。

语法

public int hashCode()

参数

不需要参数。

返回值

返回哈希码此对象的值。

异常

示例:

在下面的示例中,java.util.Calendar.hashCode() 方法返回给定 Calendar 对象的哈希代码值。

import java.util.*;

public class MyClass {
  public static void main(String[] args) {
    //创建日历实例
    Calendar Cal = Calendar.getInstance();

    //从日历创建日期对象并打印它
    System.out.println("The Calendar is: " + Cal.getTime());

    //打印Calendar实例的哈希码
    System.out.println("The hashCode is: " + Cal.hashCode());    
  }
}

上述代码的输出将是:

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