當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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

程序2

// 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://docs.oracle.com/javase/8/docs/api/java/time/OffsetTime.html#hashCode–



相關用法


注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 OffsetTime hashCode() in Java with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。