Java Calendar equals() MethodThe 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. SyntaxParameterObject : Object to be compared ReturnsIt returns a Boolean value. ThrowsDo not throw any exception. Example 1Test it NowOutput: Wed Aug 01 02:31:56 PDT 2018 Wed Aug 01 02:31:57 PDT 2018 Cal1 and Cal2 are equal:false Example 2Test it NowOutput: Wed Aug 01 02:34:20 PDT 2018 Wed Aug 01 02:34:20 PDT 2018 Cal1 and Cal2 are equal:true Example 3Test it NowOutput: Wed Aug 01 02:36:22 PDT 2018 Wed Aug 01 02:36:22 PDT 2018 Cal1 and Cal2 are equal:false
Next TopicJava Calendar Class
|