YearMonth equals() method in Java
The equals() method of YearMonth class in Java is used to compare two YearMonth objects. It compares this YearMonth object to the YearMonth object passed to it as parameter and checks if two YearMonth instances are equal or not.
Syntax:
public boolean equals(Object otherYearMonth)
Parameter: This method accepts a single parameter otherYearMonth which is the other YearMonth instance with which this YearMonth is to be compared.
Return Value: It returns true if this YearMonth is equal to otherYearMonth otherwise it returns False.
Below programs illustrate the equals() method of YearMonth in Java:
Program 1:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
YearMonth firstYearMonth = YearMonth.of( 2017 , 8 );
YearMonth secondYearMonth = YearMonth.of( 2016 , 11 );
System.out.println(firstYearMonth.equals(secondYearMonth));
}
}
|
Program 2:
import java.util.*;
import java.time.*;
public class GfG {
public static void main(String[] args)
{
YearMonth firstYearMonth = YearMonth.of( 2017 , 8 );
YearMonth secondYearMonth = YearMonth.of( 2017 , 8 );
System.out.println(firstYearMonth.equals(secondYearMonth));
}
}
|
Reference: https://docs.oracle.com/javase/8/docs/api/java/time/YearMonth.html#equals-java.lang.Object-
Last Updated :
28 Nov, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...