Java中的MonthDay hashCode()方法
可以使用hashCode()Java中MonthDay类中的方法获取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());