📌  相关文章
📜  Java中的 WeekFields equals() 方法及示例

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

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

WeekFields 类equals()方法用于比较此 WeekFields 是否等于作为参数传递的指定对象。比较基于规则的整个状态,即每周的第一天和最少的几天。

句法:

public boolean equals(Object object)

参数:此方法接受要比较的其他规则的对象,null 返回 false。

返回值:如果这等于指定的规则,则此方法返回 true。

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

// Java program to demonstrate
// WeekFields.equals() 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);
        WeekFields otherWeekFields
            = WeekFields.of(DayOfWeek.MONDAY, 1);
  
        // apply equals()
        boolean bothAreEquals
            = weekFields.equals(otherWeekFields);
  
        // print results
        System.out.println("Equals: "
                           + bothAreEquals);
    }
}
输出:
Equals: true

方案二:

// Java program to demonstrate
// WeekFields.equals() 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);
        WeekFields otherWeekFields
            = WeekFields.of(DayOfWeek.SUNDAY, 3);
  
        // apply equals()
        boolean bothAreEquals
            = weekFields.equals(otherWeekFields);
  
        // print results
        System.out.println("Equals: "
                           + bothAreEquals);
    }
}
输出:
Equals: false

参考资料:https: Java Java)