Java ZoneId hashCode()方法及示例
Java中 ZoneId 类的 hashCode() 方法用于返回该ZoneId的唯一哈希码。
语法
public int hashCode(Object obj)
参数: 此方法不接受任何东西。
返回值: 该方法返回 一个 代表hashCode的 int 。
以下程序说明了hashCode()方法:
程序1 :
// Java program to demonstrate
// ZoneId.hashCode() method
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// create ZoneId object
ZoneId zoneId
= ZoneId.of("Europe/Paris");
// get and print hashcode
System.out.println("hashcode: "
+ zoneId.hashCode());
}
}
输出。
hashcode: -672549154
程序2
// Java program to demonstrate
// ZoneId.hashCode() method
import java.time.*;
public class GFG {
public static void main(String[] args)
{
// create ZoneId object
ZoneId zoneId
= ZoneId.of("Asia/Calcutta");
// get and print hashcode
System.out.println("hashcode: "
+ zoneId.hashCode());
}
}
输出。
hashcode: -681304890
参考资料:
https://docs.oracle.com/javase/10/docs/api/java/time/ZoneId.html#hashCode()
极客教程