MonthDay equals() method in Java with Examples
The equals() method of MonthDay class in Java checks if this month-day is equal to another month-day.
Syntax:
public boolean equals(Object obj)
Parameter: This method accepts a parameter obj which specifies if this month-day is equal to another month-day.
Returns: The function returns true if this is equal to the other time.
Below programs illustrate the MonthDay.equals() method:
Program 1:
// Program to illustrate the equals() method import java.util.*; import java.time.*; public class GfG { public static void main(String[] args) { // Parses the date MonthDay tm1 = MonthDay.parse("--12-06"); // Uses the function LocalDate dt1 = tm1.atYear(2018); // Parses the date MonthDay tm2 = MonthDay.parse("--12-06"); // Uses the function LocalDate dt2 = tm2.atYear(2018); // Prints the date System.out.println(dt1.equals(dt2)); } } |
true
Program 2:
// Program to illustrate the equals() method import java.util.*; import java.time.*; public class GfG { public static void main(String[] args) { // Parses the date MonthDay tm1 = MonthDay.parse("--10-06"); // Uses the function LocalDate dt1 = tm1.atYear(2018); // Parses the date MonthDay tm2 = MonthDay.parse("--12-06"); // Uses the function LocalDate dt2 = tm2.atYear(2018); // Prints the date System.out.println(dt1.equals(dt2)); } } |
false
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/MonthDay.html#equals-java.lang.Object-
Recommended Posts:
- MonthDay with() Method in Java with Examples
- MonthDay get() method in Java with Examples
- MonthDay from() method in Java with Examples
- MonthDay isSupported() Method in Java with Examples
- MonthDay query() method in Java with Examples
- MonthDay withDayOfMonth() Method in Java with Examples
- MonthDay hashCode() method in Java with Examples
- MonthDay isAfter() Method in Java with Examples
- MonthDay atYear() method in Java with Examples
- MonthDay isBefore() Method in Java with Examples
- MonthDay isValidYear() Method in Java with Examples
- MonthDay withMonth() Method in Java with Examples
- MonthDay range() method in Java with Examples
- MonthDay compareTo() method in Java with Examples
- MonthDay getMonth() method in Java with Examples
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.



