Javatpoint Logo
Javatpoint Logo

Java Calendar equals() Method

The equals() method compares two objects for equality and returns true if they are equal. The equals() method is provided in the Object class. As object class is the super class of all other classes in java. Calendar class inherits the equals() method. It compares this (current calendar object) calendar to the specified Object. The result is true if and only if the argument is a Calendar object of the same calendar system that represents the same time value under the same Calendar parameters as this object.

Syntax

Parameter

Object : Object to be compared

Returns

It returns a Boolean value.

Throws

Do not throw any exception.

Example 1

Test it Now

Output:

Wed Aug 01 02:31:56 PDT 2018
Wed Aug 01 02:31:57 PDT 2018
Cal1 and Cal2 are equal:false

Example 2

Test it Now

Output:

Wed Aug 01 02:34:20 PDT 2018
Wed Aug 01 02:34:20 PDT 2018
Cal1 and Cal2 are equal:true

Example 3

Test it Now

Output:

Wed Aug 01 02:36:22 PDT 2018
Wed Aug 01 02:36:22 PDT 2018
Cal1 and Cal2 are equal:false



Help Others, Please Share

facebook twitter pinterest