Java ChronoPeriod hashCode()方法及示例
Java中 ChronoPeriod类 的 hashCode()方法 是用来获取该周期生成的hashCode的。
语法
int hashCode()
参数: 该方法不接受任何参数。
返回值: 该方法返回为给定周期生成的hashCode。
以下程序说明了Java中的hashCode()方法。
程序1 :
// Java code to show the function hashCode()// to get the hashCode for the given period import java.time.*;import java.time.chrono.*;import java.time.temporal.ChronoUnit; public class ChronoPeriodDemo { // Function to generate hashCode for the given period static void getNumberOfDays(int year, int months, int days) { ChronoPeriod period = Period.of(year, months, days); System.out.println(period.hashCode()); } // Driver Code public static void main(String[] args) { int year = 12; int months = 3; int days = 31; getNumberOfDays(year, months, days); }}
输出:
2032396
程序2 :
// Java code to show the function hashCode()// to get the hashCode for the given period import java.time.*;import java.time.chrono.*;import java.time.temporal.ChronoUnit; public class ChronoPeriodDemo { // Function to generate hashCode for the given period static void getNumberOfDays(int year, int months, int days) { ChronoPeriod period = Period.of(year, months, days); System.out.println(period.hashCode()); } // Driver Code public static void main(String[] args) { int year = -12; int months = 3; int days = 31; getNumberOfDays(year, months, days); }}输出:
2032372
参考资料 : https://docs.oracle.com/javase/9/docs/api/java/time/chrono/ChronoPeriod.html#hashCode-
