Java中的 OffsetTime hashCode() 示例
Java中 OffsetTime 类的hashCode()方法用于获取此 Time 实例的哈希码。
句法 :
public int hashCode()
参数:此方法接受不接受任何参数。
返回值:返回合适的哈希码。
下面的程序说明了hashCode()方法:
程序 1:
// Java program to demonstrate the hashCode() method
import java.time.OffsetTime;
public class GFG {
public static void main(String[] args)
{
// Parses the time
OffsetTime time = OffsetTime.parse("15:10:30+07:00");
// gets the hash-code in time
System.out.println("hash-code: " + time.hashCode());
}
}
输出:
hash-code: -1984024609
方案二:
// Java program to demonstrate the hashCode() method
import java.time.OffsetTime;
public class GFG {
public static void main(String[] args)
{
// Parses the time
OffsetTime time = OffsetTime.parse("11:30:30+06:00");
// gets the hash-code in time
System.out.println("hash-code: " + time.hashCode());
}
}
输出:
hash-code: 745450958
参考:https: Java/time/OffsetTime.html#hashCode–