WeekFields equals() method in Java with Examples

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

Equals: true

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

Equals: false

References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/WeekFields.html#equals(java.lang.Object)

java-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.