WeekFields类的equals()方法用于比较此WeekFields是否等于作为参数传递的指定对象。比较是基于规则的整个状态,即第一笔day-of-week和最少的天数。
用法:
public boolean equals(Object object)
参数:此方法接受与其他规则进行比较的对象,null返回false。
返回值:如果等于指定的规则,则此方法返回true。
以下示例程序旨在说明WeekFields.equals()方法:
程序1:
// 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
程序2:
// 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://docs.oracle.com/javase/10/docs/api/java/time/temporal/WeekFields.html#equals(java.lang.Object)
相关用法
- Java WeekFields of()用法及代码示例
- Java WeekFields weekOfYear()用法及代码示例
- Java WeekFields weekOfWeekBasedYear()用法及代码示例
- Java WeekFields dayOfWeek()用法及代码示例
- Java WeekFields hashCode()用法及代码示例
- Java WeekFields toString()用法及代码示例
- Java WeekFields weekBasedYear()用法及代码示例
- Java WeekFields getMinimalDaysInFirstWeek()用法及代码示例
- Java WeekFields getFirstDayOfWeek()用法及代码示例
- Java WeekFields weekOfMonth()用法及代码示例
- Java Map equals()用法及代码示例
- Java Set equals()用法及代码示例
- Java List equals()用法及代码示例
- Java Optional equals()用法及代码示例
- Java Year equals()用法及代码示例
注:本文由纯净天空筛选整理自AmanSingh2210大神的英文原创作品 WeekFields equals() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。