- Java.util Package Classes
- Java.util - Home
- Java.util - ArrayDeque
- Java.util - ArrayList
- Java.util - Arrays
- Java.util - BitSet
- Java.util - Calendar
- Java.util - Collections
- Java.util - Currency
- Java.util - Date
- Java.util - Dictionary
- Java.util - EnumMap
- Java.util - EnumSet
- Java.util - Formatter
- Java.util - GregorianCalendar
- Java.util - HashMap
- Java.util - HashSet
- Java.util - Hashtable
- Java.util - IdentityHashMap
- Java.util - LinkedHashMap
- Java.util - LinkedHashSet
- Java.util - LinkedList
- Java.util - ListResourceBundle
- Java.util - Locale
- Java.util - Observable
- Java.util - PriorityQueue
- Java.util - Properties
- Java.util - PropertyPermission
- Java.util - PropertyResourceBundle
- Java.util - Random
- Java.util - ResourceBundle
- Java.util - ResourceBundle.Control
- Java.util - Scanner
- Java.util - ServiceLoader
- Java.util - SimpleTimeZone
- Java.util - Stack
- Java.util - StringTokenizer
- Java.util - Timer
- Java.util - TimerTask
- Java.util - TimeZone
- Java.util - TreeMap
- Java.util - TreeSet
- Java.util - UUID
- Java.util - Vector
- Java.util - WeakHashMap
- Java.util Package Extras
- Java.util - Interfaces
- Java.util - Exceptions
- Java.util - Enumerations
- Java.util Useful Resources
- Java.util - Useful Resources
- Java.util - Discussion
Java.util.GregorianCalendar.equals() Method
Description
The java.util.GregorianCalendar.equals() method compares this GregorianCalendar to the specified Object. The result is true if and only if the argument is a GregorianCalendar object that represents the same time value (millisecond offset from the Epoch) under the same Calendar parameters and Gregorian change date as this object.
Declaration
Following is the declaration for java.util.GregorianCalendar.equals() method
public boolean equals(Object obj)
Parameters
obj − the object to compare with.
Return Value
This method returns true if this object is equal to obj; false otherwise.
Exception
NA
Example
The following example shows the usage of java.util.GregorianCalendar.equals() method.
package com.tutorialspoint; import java.util.*; public class GregorianCalendarDemo { public static void main(String[] args) { // create a new calendar GregorianCalendar cal1 = (GregorianCalendar) GregorianCalendar.getInstance(); // print the current date and time System.out.println("" + cal1.getTime()); // create a second calendar equal to first one GregorianCalendar cal2 = (GregorianCalendar) (Calendar) cal1.clone(); // print cal2 System.out.println("" + cal2.getTime()); // compare the two calendars System.out.println("Cal1 and Cal2 are equal:" + cal1.equals(cal2)); // change cal 2 a bit cal2.add(GregorianCalendar.YEAR, 5); // compare the two calendars System.out.println("Cal1 and Cal2 are equal:" + cal1.equals(cal2)); } }
Let us compile and run the above program, this will produce the following result −
Fri May 18 02:40:39 EEST 2012 Fri May 18 02:40:39 EEST 2012 Cal1 and Cal2 are equal:true Cal1 and Cal2 are equal:false
java_util_gregoriancalendar.htm
Advertisements