Java中的YearMonth類的hashCode()方法用於為此使用的YearMonth實例創建合適的哈希碼。
用法:
public int hashCode()
參數:此方法不接受任何參數。
返回值:它為此YearMonth實例返回合適的整數哈希碼值。
以下程序說明了Java中YearMonth的hashCode()方法:
示例1::
// Program to illustrate the hashCode() method
import java.util.*;
import java.time.*;
import java.time.format.DateTimeFormatter;
public class GfG {
public static void main(String[] args)
{
// Create a YearMonth object
YearMonth thisYearMonth = YearMonth.of(2017, 8);
// Get the hash code value
System.out.println(thisYearMonth.hashCode());
}
}
輸出:
1073743841
示例2::
// Program to illustrate the hashCode() method
import java.util.*;
import java.time.*;
import java.time.format.DateTimeFormatter;
public class GfG {
public static void main(String[] args)
{
// Create a YearMonth object
YearMonth thisYearMonth = YearMonth.of(2018, 5);
// Get the hash code value
System.out.println(thisYearMonth.hashCode());
}
}
輸出:
671090658
參考: https://docs.oracle.com/javase/8/docs/api/java/time/YearMonth.html#hashCode-
相關用法
- Java YearMonth atEndOfMonth()用法及代碼示例
- Java YearMonth with()用法及代碼示例
- Java YearMonth atDay()用法及代碼示例
- Java YearMonth equals()用法及代碼示例
- Java YearMonth format()用法及代碼示例
- Java YearMonth compareTo()用法及代碼示例
- Java YearMonth until()用法及代碼示例
- Java YearMonth getYear()用法及代碼示例
- Java YearMonth getMonthValue()用法及代碼示例
- Java YearMonth getMonth()用法及代碼示例
- Java YearMonth lengthOfYear()用法及代碼示例
- Java YearMonth range()用法及代碼示例
- Java YearMonth withMonth()用法及代碼示例
- Java YearMonth withYear()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 YearMonth hashCode() method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。