WeekFields equals() method in Java with Examples
Last Updated :
29 Jan, 2020
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:
import java.time.DayOfWeek;
import java.time.temporal.WeekFields;
public class GFG {
public static void main(String[] args)
{
WeekFields weekFields
= WeekFields.of(DayOfWeek.MONDAY, 1 );
WeekFields otherWeekFields
= WeekFields.of(DayOfWeek.MONDAY, 1 );
boolean bothAreEquals
= weekFields.equals(otherWeekFields);
System.out.println( "Equals: "
+ bothAreEquals);
}
}
|
Program 2:
import java.time.DayOfWeek;
import java.time.temporal.WeekFields;
public class GFG {
public static void main(String[] args)
{
WeekFields weekFields
= WeekFields.of(DayOfWeek.MONDAY, 1 );
WeekFields otherWeekFields
= WeekFields.of(DayOfWeek.SUNDAY, 3 );
boolean bothAreEquals
= weekFields.equals(otherWeekFields);
System.out.println( "Equals: "
+ bothAreEquals);
}
}
|
References: https://docs.oracle.com/javase/10/docs/api/java/time/temporal/WeekFields.html#equals(java.lang.Object)
Share your thoughts in the comments
Please Login to comment...