📌  相关文章
📜  Java中的 ZoneOffsetTransition hashCode() 方法与示例

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

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

Java.time.zone.ZoneOffsetTransition类的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
        // the object of LocalDateTime
        LocalDateTime loc
            = LocalDateTime.of(
                1999, 04, 25,
                03, 24, 45, 0);
  
        // creating and initializing
        // the object of ZoneOffset
        ZoneOffset off1
            = ZoneOffset.ofTotalSeconds(8);
  
        // creating and initializing
        // the object of ZoneOffset
        ZoneOffset off2
            = ZoneOffset.ofTotalSeconds(12);
  
        // creating and initializing
        // ZoneOffsetTransition Object
        ZoneOffsetTransition zonetrans1
            = ZoneOffsetTransition.of(
                loc, off1, off2);
  
        // getting the hash code for this object
        // by using hashcode() method
        int hash = zonetrans1.hashCode();
  
        // display the result
        System.out.println("hashcode : " + hash);
    }
}
输出:
hashcode : 1396559933

示例 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
        // the object of LocalDateTime
        LocalDateTime loc
            = LocalDateTime.of(
                2010, 04, 25,
                03, 56, 45, 0);
  
        // creating and initializing
        // the object of ZoneOffset
        ZoneOffset off1
            = ZoneOffset.ofTotalSeconds(8);
  
        // creating and initializing
        // the object of ZoneOffset
        ZoneOffset off2
            = ZoneOffset.ofTotalSeconds(12);
  
        // creating and initializing
        // ZoneOffsetTransition Object
        ZoneOffsetTransition zonetrans1
            = ZoneOffsetTransition.of(
                loc, off1, off2);
  
        // getting the hash code for this object
        // by using hashcode() method
        int hash = zonetrans1.hashCode();
  
        // display the result
        System.out.println("hashcode : " + hash);
    }
}
输出:
hashcode : 1539866618

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