📜  Java中的 WeekFields hashCode() 方法及示例

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

Java中的 WeekFields hashCode() 方法及示例

WeekFields 类hashCode()方法用于返回此 WeekFields 的哈希码。它返回一个整数值,该整数值是此 ValueRange 实例的 hashCode 值。

句法:

public int hashCode()

参数:此方法不接受任何内容。

返回值:此方法返回整数值,即 hashCode 值。

下面的程序说明了 WeekFields.hashCode() 方法:
方案一:

// Java program to demonstrate
// WeekFields.hashCode() method
  
import java.time.DayOfWeek;
import java.time.temporal.WeekFields;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // create WeekFields
        WeekFields weekFields
            = WeekFields.of(DayOfWeek.MONDAY, 1);
  
        // apply hashCode()
        int hashCode = weekFields.hashCode();
  
        // print results
        System.out.println("Hash Code:"
                           + hashCode);
    }
}
输出:
Hash Code:1

方案二:

// Java program to demonstrate
// WeekFields.hashCode() method
  
import java.time.DayOfWeek;
import java.time.temporal.WeekFields;
import java.util.Locale;
  
public class GFG {
    public static void main(String[] args)
    {
  
        Locale locale = new Locale("EN", "US");
  
        // create WeekFields
        WeekFields weekFields
            = WeekFields.of(locale);
  
        // apply hashCode()
        int hashCode = weekFields.hashCode();
  
        // print results
        System.out.println("Hash Code:"
                           + hashCode);
    }
}
输出:
Hash Code:43

参考:https: Java/time/temporal/WeekFields.html#hashCode()