ChronoPeriod equals() method in Java with Examples
Last Updated :
27 Jun, 2019
The equals() method of ChronoPeriod interface in Java is used to check if two given periods are equal or not.
The comparison is based on the type ChronoPeriod and each of the three years, months and date. To be equal, all of the three years, month and date must be individually equal.
Syntax:
boolean equals(ChronoPeriod secondChronoPeriod)
Parameters: This method accepts a single parameter secondChronoPeriod which is the another period to compare with.
Return Value: The above methods returns true if given periods are equal, else it returns false.
Below programs illustrate the above method:
Program 1:
import java.time.*;
import java.time.chrono.*;
public class ChronoPeriodClass {
static boolean
checkIfEqualChronoPeriod(ChronoPeriod firstChronoPeriod,
ChronoPeriod secondChronoPeriod)
{
return firstChronoPeriod.equals(secondChronoPeriod);
}
public static void main(String[] args)
{
ChronoPeriod first = Period.ofDays( 28 );
ChronoPeriod second = Period.ofDays( 8 );
System.out.println(
checkIfEqualChronoPeriod(first, second));
}
}
|
Program 2:
import java.time.*;
import java.time.chrono.*;
public class ChronoPeriodClass {
static boolean
checkIfEqualChronoPeriod(ChronoPeriod firstChronoPeriod,
ChronoPeriod secondChronoPeriod)
{
return firstChronoPeriod.equals(secondChronoPeriod);
}
public static void main(String[] args)
{
ChronoPeriod first2 = Period.ofDays( 28 );
ChronoPeriod second2 = Period.ofDays( 28 );
System.out.println(
checkIfEqualChronoPeriod(first2, second2));
}
}
|
Reference: https://docs.oracle.com/javase/9/docs/api/java/time/chrono/ChronoPeriod.html#equals-java.lang.Object-
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...