Java 中的 MonthDay hashCode() 方法


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

演示此內容的一個程式如下所示

示例

 線上演示

import java.time.*;
public class Demo {
   public static void main(String[] args) {  
      MonthDay md = MonthDay.parse("--02-21");
      System.out.println("The MonthDay is: " + md);
      System.out.println("The hash code is: " + md.hashCode());
   }
}

輸出

The MonthDay is: --02-21
The hash code is: 149

現在讓我們瞭解一下上述程式。

首先顯示 MonthDay。然後使用 hashCode() 方法獲取 MonthDay 的雜湊碼值並顯示該值。演示此內容的程式碼片段如下所示

MonthDay md = MonthDay.parse("--02-21");
System.out.println("The MonthDay is: " + md);
System.out.println("The hash code is: " + md.hashCode());

更新於: 30-Jul-2019

94 次檢視

開啟職業生涯

完成課程以獲得認證

入門
廣告
© . All rights reserved.