Calendar類中的hashCode()方法用於返回此Calendar對象的哈希碼。
用法:
public int hashCode()
參數:該方法不包含任何參數。
返回值:該方法返回此日曆對象的哈希碼值。
以下示例程序旨在說明Calendar類的hashCode()方法的用法:
示例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
示例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
參考: https://docs.oracle.com/javase/8/docs/api/java/util/Calendar.html#hashCode–
相關用法
- Java Calendar set()用法及代碼示例
- Java Calendar add()用法及代碼示例
- Java Calendar get()用法及代碼示例
- Java Calendar getLeastMaximum()用法及代碼示例
- Java Calendar getTime()用法及代碼示例
- Java Calendar getInstance()用法及代碼示例
- Java Calendar getFirstDayOfWeek()用法及代碼示例
- Java Calendar getMaximum()用法及代碼示例
- Java Calendar isLenient()用法及代碼示例
- Java Calendar getTimeInMillis()用法及代碼示例
- Java Calendar getMinimum()用法及代碼示例
- Java Calendar getMinimalDaysInFirstWeek()用法及代碼示例
- Java Calendar getDisplayNames()用法及代碼示例
- Java Calendar getDisplayName()用法及代碼示例
- Java Calendar complete()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 Calendar hashCode() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。