📜  Java中的 ZoneOffsetTransitionRule hashCode() 方法与示例

📅  最后修改于: 2022-05-13 01:54:40.678000             🧑  作者: Mango

Java中的 ZoneOffsetTransitionRule hashCode() 方法与示例

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

参考: https://docs.oracle.com/javase/9/docs/api/ Java/time/zone/ZoneOffsetTransitionRule.html#hashCode–