Java Calendar hashCode()方法
java的hasgCode()方法是对象类的方法,而对象类是java中所有类的最终超类。 hashCode()方法被Java中的所有其他类重载。此方法返回日历对象的哈希码。
语法
参数
未传递任何参数。
返回
日历对象的哈希码值。
抛出
不抛出异常。
示例1
import java.util.*;
public class JavaCalendarhashCodeExample1 {
public static void main(String[] args) {
// create a calendar
Calendar mycal = Calendar.getInstance();
// display current calendar
System.out.println("The current time: " + mycal.getTime());
// get the hash code and print it
int i = mycal.hashCode();
System.out.println(" Hash Code " + i);
}
}
输出:
The current time: Fri Aug 10 11:38:27 PDT 2018
Hash Code 999473001
示例2
import java.util.*;
public class JavaCalendarhashCodeExample2 {
public static void main(String[] args) {
// create a new calendar
GregorianCalendar mycal = (GregorianCalendar) GregorianCalendar.getInstance();
// print the current date and time
System.out.println(" current Time : " + mycal.getTime());
// print a hashcode for this calendar
System.out.println("Hash Code:" + mycal.hashCode());
}
}
输出:
current Time : Fri Aug 10 11:48:02 PDT 2018
Hash Code:999946776