Java LocalDate isEqual() Method

Java isEqual() method is used to check if two dates are equal or not. It is helpful to check the date is equal to another date, for example, we have two dates 2012/12/10 and 2012/12/12 then using the isEqual() method will return false.

It takes an argument of ChronoLocalDate type and returns either true or false. The syntax of the method is given below.

Syntax

public boolean isEqual(ChronoLocalDate other)

Parameters:

other - the other date to compare.

Returns:

It reurns true if this date is equal to the specified date.

Time for an Example

Let's take an example to check whether the two dates are equal or not. Here, we are using two different dates and checking with the method that returns false.

import java.time.LocalDate; 
public class DateDemo {
	
	public static void main(String[] args){  
		
		LocalDate localDate = LocalDate.of(2015, 10, 21);
		System.out.println(localDate);
		// Date 2
		LocalDate localDate2 = LocalDate.of(2016, 10, 21);
		System.out.println(localDate2);
		boolean d  = localDate.isEqual(localDate2);
		System.out.println("is date1 is equal date2 : "+d);
	}
}


2015-10-21
2016-10-21
is date1 is equal date2 : false

Time for another Example

Let's take another example to understand the use of isEqual() method. Here, we are using two different dates and applying isEqual() method that returns true. See the below example.

import java.time.LocalDate; 
public class DateDemo {
	
	public static void main(String[] args){  
		
		LocalDate localDate = LocalDate.of(2015, 10, 21);
		System.out.println(localDate);
		// Date 2
		LocalDate localDate2 = LocalDate.of(2015, 10, 21);
		System.out.println(localDate2);
		boolean d  = localDate.isEqual(localDate2);
		System.out.println("is date1 is equal date2 : "+d);
	}
}


2015-10-21
2015-10-21
is date1 is equal date2 : true

Live Example:

Try with a live example, execute the code instantly with our powerful Online Java Compiler.