The equals() method of WeekFields class is used to compare if this WeekFields is equal to the specified object which was passed as a parameter. The comparison is based on the entire state of the rules, which is the first day-of-week and minimal days.
Syntax:
public boolean equals(Object object)
Parameters: This method accepts object which is the other rules to compare to, null returns false.
Return value: This method returns true if this is equal to the specified rules.
Below programs illustrate the WeekFields.equals() method:
Program 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
Program 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
References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/WeekFields.html#equals(java.lang.Object)