Java Duration hashCode()方法及实例
java.time包中Duration类的hashCode()方法用于获取该期限的hashCode值。
语法。
public int hashCode()
参数。此方法不接受任何参数。
返回值。该方法返回一个int值,即该期限的hashCode值。
下面的例子说明了Duration.hashCode()方法。
例1:
// Java code to illustrate hashCode() method import java.time.Duration; public class GFG { public static void main(String[] args) { // Duration using parse() method Duration duration = Duration.parse("P2DT3H4M"); // Get the hashCode value // using hashCode() method System.out.println(duration.hashCode()); }}
输出:
183840
例2:
// Java code to illustrate hashCode() method import java.time.Duration; public class GFG { public static void main(String[] args) { // Duration using ofHours() method Duration duration = Duration.ofHours(5); // Get the hashCode value // using hashCode() method System.out.println(duration.hashCode()); }}输出:
18000
参考资料: https://docs.oracle.com/javase/9/docs/api/java/time/Duration.html#hashCode-
