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–
相关用法
- Java ChronoPeriod plus()用法及代码示例
- Java ChronoPeriod between()用法及代码示例
- Java ChronoPeriod get()用法及代码示例
- Java ChronoPeriod isNegative()用法及代码示例
- Java ChronoPeriod isZero()用法及代码示例
- Java ChronoPeriod negated()用法及代码示例
- Java ChronoPeriod minus()用法及代码示例
- Java ChronoPeriod negated()用法及代码示例
- Java ChronoPeriod getChronology()用法及代码示例
- Java ChronoPeriod addTo()用法及代码示例
- Java ChronoPeriod subtractFrom()用法及代码示例
- Java ChronoPeriod multipliedBy()用法及代码示例
- Java ChronoPeriod equals()用法及代码示例
- Java ChronoPeriod toString()用法及代码示例
- Java ChronoPeriod getUnits()用法及代码示例
注:本文由纯净天空筛选整理自srinam大神的英文原创作品 ChronoPeriod hashCode() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。