Java 中的 Instant hashCode() 方法


可以使用 Java 中 Instant 類的 hashCode() 方法來獲取特定 Instant 物件的雜湊碼。此方法不需要任何引數,它會返回 Instant 物件的雜湊碼。

以下是演示此內容的程式

示例

 動態演示

import java.time.*;
import java.time.temporal.ChronoUnit;
public class Demo {
   public static void main(String[] args) {
      Instant i = Instant.now();
      System.out.println("The current instant is: " + i);
      int hashCode = i.hashCode();
      System.out.println("The Hash Code value for the instant is: " + hashCode);
   }
}

輸出

The current instant is: 2019-02-13T12:05:21.488Z
The Hash Code value for the instant is: 668255745

現在讓我們瞭解以上程式。

首先顯示當前瞬間。然後使用 hashCode() 方法獲取該 Instant 的雜湊碼,並顯示該雜湊碼。演示此內容的程式碼片段如下

Instant i = Instant.now();
System.out.println("The current instant is: " + i);
int hashCode = i.hashCode();
System.out.println("The Hash Code value for the instant is: " + hashCode);

更新於:30-7-2019

151 次瀏覽

開啟您的職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.