Java 中 Duration hashCode() 方法
可以使用 Java 中 Duration 类的 hashCode() 方法获取持续时间的哈希码值。此方法不需要参数,它会返回持续时间的哈希码值。
演示此方法的程序如下 −
示例
import java.time.Duration;
public class Demo {
public static void main(String[] args) {
Duration d = Duration.ofDays(2);
System.out.println("The duration is: " + d);
System.out.println("The hash code of the duration is: " + d.hashCode());
}
}输出
The duration is: PT48H The hash code of the duration is: 172800
现在我们来理解一下上述程序。
显示持续时间,然后使用 hashCode() 方法获取持续时间的哈希码值并显示。演示此方法的代码片段如下 −
Duration d = Duration.ofDays(2);
System.out.println("The duration is: " + d);
System.out.println("The hash code of the duration is: " + d.hashCode());
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP