Java.util.Calendar.equals() Method


Advertisements


Description

The java.util.Calendar.equals() method compares this Calendar to the specified Object.

Declaration

Following is the declaration for java.util.Calendar.equals() method

public boolean equals(Object obj)

Parameters

  • obj − the object to compare with.

Return Value

true if this object is equal to obj; false if there is any difference in those parameters between the two Calendars (millisecond offset from the Epoch).

Exception

NA

Example

The following example shows the usage of java.util.calendar.equal() method.

Live Demo
package com.tutorialspoint;

import java.util.*;

public class CalendarDemo {
   public static void main(String[] args) {

      // create two calendars
      Calendar cal = Calendar.getInstance();

      // specify a date for one of them
      Calendar cal2 = new GregorianCalendar(2011, 04, 29);

      // compare the two calendars.
      boolean b = cal.equals(cal2);

      // print result
      System.out.println("Calendars are equal :" + b);
   }
}

Let us compile and run the above program, this will produce the following result −

Calendars are equal :false

java_util_calendar.htm

Advertisements
E-Books Store