Java 中的 ZoneOffsetTransitionRule hashCode()方法,示例
原文:https://www . geeksforgeeks . org/zoneoffsettransitionrule-hashcode-method-in-Java-with-example/
使用Java . time . zone . zoneoffsettransitionrule类的 hashCode() 方法获取该区域偏移转换规则对象的哈希代码。
语法:
public int hashCode()
参数:该方法不接受任何参数。
返回值:该方法返回该区域偏移过渡规则对象的哈希码。
下面是举例说明 hashCode() 方法的例子:
例 1:
// Java program to demonstrate
// hashCode() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.zone.*;
public class GFG {
public static void main(String[] argv)
{
// creating and initializing
// ZoneOffsetTransitionRule Object
ZoneOffsetTransitionRule zonetrans1
= ZoneOffsetTransitionRule
.of(
Month.JANUARY, 12,
DayOfWeek.SUNDAY,
LocalTime.of(03, 24, 45),
false,
ZoneOffsetTransitionRule
.TimeDefinition
.STANDARD,
ZoneOffset.ofTotalSeconds(8),
ZoneOffset.ofTotalSeconds(17),
ZoneOffset.ofTotalSeconds(12));
// getting the hash code
// by using hashCode() method
int hash = zonetrans1.hashCode();
// display the result
System.out.println("hash code : " + hash);
}
}
输出:
hash code : 402556303
例 2:
// Java program to demonstrate
// hashCode() method
import java.util.*;
import java.io.*;
import java.time.*;
import java.time.chrono.*;
import java.time.zone.*;
public class GFG {
public static void main(String[] argv)
{
// creating and initializing
// ZoneOffsetTransitionRule Object
ZoneOffsetTransitionRule zonetrans1
= ZoneOffsetTransitionRule
.of(
Month.JANUARY, 12,
DayOfWeek.SUNDAY,
LocalTime.of(06, 24, 45),
false,
ZoneOffsetTransitionRule
.TimeDefinition
.STANDARD,
ZoneOffset.ofTotalSeconds(8),
ZoneOffset.ofTotalSeconds(17),
ZoneOffset.ofTotalSeconds(12));
// getting the hash code
// by using hashCode() method
int hash = zonetrans1.hashCode();
// display the result
System.out.println("hash code : " + hash);
}
}
输出:
hash code : 756450703
版权属于:月萌API www.moonapi.com,转载请注明出处