The equals(Object otherInstant) method of Instant class is used to compare this Instant to the Instant object passed as parameter. The comparison between both instances is based on the time-line position of the instants. The value to be returned by this method is determined as follows:
- if both instances are equal, then true is returned
- if both instances are not equal, then false is returned.
public boolean equals(Object otherInstant)
Parameters: This method accepts a mandatory parameter otherInstant which is the other instant to be compared, and it should not be null.
Return Value: This method returns a boolean value as follows:
- true: if both instances are equal.
- false: if both instances are not equal.
Below programs illustrate the Instant.equals() method:
Program 1: When both instances are equal
Instant1: 2018-10-20T16:55:30Z Instant2: 2018-10-20T16:55:30Z Are both instants are equal: true
Program 2: When both instances are not equal
Instant1: 2018-10-20T16:55:30Z Instant2: 2011-10-20T16:55:30Z Are both instants are equal: false
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.