Home » Java programming language

Java Date equals() Method with Example

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

Date Class equals() method

  • equals() method is available in java.util package.
  • equals() method is used to check whether this date and the given object (o) are equals 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 checking equality of this date object with the given object (o).


    public boolean equals(Object o);


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

Return value:

The return type of this method is boolean, it returns true when two date objects are equals otherwise it returns false.


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

import java.util.*;

public class EqualsOfDate {
    public static void main(String[] args) {
        // create two Date object with two dates
        Date this_date = new Date(2016, 8, 20);
        Date given_date = new Date(2010, 11, 30);

        // By using equals() method is to check 
        // equality of this_date and the given_date
        boolean status = this_date.equals(given_date);

        // Display status
        System.out.println("this_date.equals(given_date): " + status);


this_date.equals(given_date): false

Comments and Discussions!

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.