Home » Java programming language

Java Calendar equals() Method with Example

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

Calendar Class equals() method

  • equals() method is available in java.util package.
  • equals() method is used to compare two Calendar objects or in other words, we can say this method is used to test the equality of this Calendar object with the given Calendar object.
  • equals() method is a non-static method, it is accessible with the class object 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 Calendar objects.


    public boolean equals(Object o);


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

Return value:

The return type of the method is boolean, it returns true when this Calendar object and the given Calendar object are same otherwise it returns false.


// Java Program to demonstrate the example of
// boolean equals(Object) method of Calendar

import java.util.*;
public class EqualsOfCalendar {
    public static void main(String[] args) {

        // Instantiating two Calendar object
        Calendar ca1 = Calendar.getInstance();
        Calendar ca2 = Calendar.getInstance();

        // By using add() method to add the 10 years
        // in ca2 to the current ca1
        ca2.add(Calendar.YEAR, 10);

        // Display ca1 and ca2
        System.out.println("ca1: " + ca1.getTime());
        System.out.println("ca2: " + ca2.getTime());

        // By using equals(Object) method is to
        // compare two calendar ca1 and ca2
        boolean status = ca1.equals(ca2);

        // Display compared result
        System.out.println("ca1.equals(ca2): " + status);


ca1: Fri Jan 24 12:39:22 GMT 2020
ca2: Thu Jan 24 12:39:22 GMT 2030
ca1.equals(ca2): 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

© some rights reserved.