Period equals() method in Java with Examples Last Updated : 27 Nov, 2018 Comments Improve Suggest changes Like Article Like Report The equals() method of Period class in Java is used to check if two given periods are equal or not. The comparison is based on the type Period and each of the three years, months and date. To be equal, all of the three year, month and date must be individually equal. Syntax: public boolean equals(Period secondPeriod) Parameters: This method accepts a single parameter secondPeriod 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: Java // Java code to show the period // equals for two given periods import java.time.LocalDate; import java.time.Period; public class PeriodClass { // Function to check if two given periods // are equals or not static boolean checkIfEqualPeriod(Period firstPeriod, Period secondPeriod) { return firstPeriod.equals(secondPeriod); } // Driver Code public static void main(String[] args) { // Given period Period first = Period.ofDays(28); Period second = Period.ofDays(8); System.out.println(checkIfEqualPeriod(first, second)); } } Output: false Program 2: Java // Java code to show the period // equals for two given periods import java.time.LocalDate; import java.time.Period; public class PeriodClass { // Function to check if two given periods // are equals or not static boolean checkIfEqualPeriod(Period firstPeriod, Period secondPeriod) { return firstPeriod.equals(secondPeriod); } // Driver Code public static void main(String[] args) { // Given period Period first2 = Period.ofDays(28); Period second2 = Period.ofDays(28); System.out.println(checkIfEqualPeriod(first2, second2)); } } Output: true Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Period.html#equals-java.lang.Object- Comment More infoAdvertise with us Next Article Period of() method in Java with Examples B barykrg Follow Improve Article Tags : Misc Java Java-Functions Java-time package Java-Period +1 More Practice Tags : JavaMisc Similar Reads Period of() method in Java with Examples The of() method of Period Class is used to obtain a period from given number of Years, Months, and Days as parameters. These parameters are accepted in the form of integers. This method returns a Period with the given number of years, months, and days. Syntax: public static Period of( int numberOfYe 2 min read Period between() method in Java with Examples The between() method of Period class in Java is used to obtain a period consisting of the number of years, months, and days between two given dates (including start date and excluding end date). This period is obtained as follows: Remove complete months. Now, calculate the remaining number of days. 2 min read Period get() method in Java with Examples The get() method of Period class in Java is used to get the value of the requested unit(YEARS, MONTHS or DAYS) given in the argument from this Period. Syntax: public long get(TemporalUnit unit) Parameters: This method accepts a single parameter unit of type TemporalUnit which is the unit to get requ 2 min read Period from() method in Java with Examples The from() method of Period class in Java is used to get an instance of Period from given temporal amount. This function obtains a period based on the amount given in argument. A TemporalAmount represents an amount of time, which may be date-based or time-based. Syntax: public static Period from(Tem 1 min read Period plus() method in Java with Examples The plus() method of Period class in Java is used to add the given amount of period to the specified period. This functions operates separately on YEAR, MONTH and DAY. Note: Normalization is not performed. 12 months and 1 year are different. Syntax: public Period plus(TemporalAmount amountToAdd) Par 2 min read Period minus() method in Java with Examples The minus() method of Period class in Java is used to subtract the given amount of period from the specified period. This functions operates separately on YEAR, MONTH and DAY. Note: Normalization is not performed. 12 months and 1 year are different. Syntax: public Period minus(TemporalAmount amountT 2 min read Like