ADVERTISEMENT
ADVERTISEMENT

Java LocalDate Class | equals() Method with Example

LocalDate Class equals() method: Here, we are going to learn about the equals() method of LocalDate Class with its syntax and example.
Submitted by Preeti Jain, on May 29, 2020

LocalDate Class equals() method

  • equals() method is available in java.time package.
  • equals() method is used to check whether this LocalDate value and the given object value are equal or not.
  • equals() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • equals() method does not throw an exception at the time of comparing two objects.

Syntax:

    public boolean equals(Object o);

Parameter(s):

  • Object o – represents the object to be compared to this LocalDate.

Return value:

The return type of this method is boolean, it returns true when both the compared objects are equal otherwise it returns false.

Example:

// Java program to demonstrate the example 
// of boolean equals(Object o) method 
// of LocalDate

import java.time.*;

public class EqualsOfLocalDate {
    public static void main(String args[]) {
        // Instantiates two LocalDate
        LocalDate l_da1 = LocalDate.parse("2007-04-04");
        LocalDate l_da2 = LocalDate.now();

        // Display l_da1,l_da2
        System.out.println("LocalDate l_da1 and l_da2: ");
        System.out.println("l_da1: " + l_da1);
        System.out.println("l_da2: " + l_da2);

        System.out.println();

        // Here, this method compares this date object
        // to the given date object for equality
        // it returns false because l_da1 <> l_da2
        boolean status = l_da1.equals(l_da2);

        // Display status
        System.out.println("l_da1.equals(l_da2): " + status);

        // Here, this method compares this date object
        // to the given date object for equality
        // it returns true because l_da1 == l_da1
        status = l_da1.equals(l_da1);

        // Display status
        System.out.println("l_da1.equals(l_da1): " + status);
    }
}

Output

LocalDate l_da1 and l_da2: 
l_da1: 2007-04-04
l_da2: 2020-05-29

l_da1.equals(l_da2): false
l_da1.equals(l_da1): true
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.