Thursday, October 23, 2025
HomeLanguagesJavaWeekFields equals() method in Java with Examples

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:




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


Output:

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


Output:

Equals: false

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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS