OptionalDouble help us to create an object which may or may not contain a Double value. The equals(Object obj) method help us to compare this OptionalDouble object with the passed object as a parameter and it returns true if objects are equal.
The other object is considered equal to this OptionalDouble if:
- it is also an OptionalDouble and;
- both instances have no value present or;
- the present values are “equal to” each other via ==.
public boolean equals(Object obj)
Parameters: This method accepts an obj which is an object to be tested for equality.
Return value: This method returns true if the other object is “equal to” this object otherwise false.
Below programs illustrate equals(Object obj) method:
OptionalDouble 1: OptionalDouble[452.13246] OptionalDouble 2: OptionalDouble[452.13246] Are both objects equal: true
OptionalDouble 1: OptionalDouble[3179464.92] OptionalDouble 2: OptionalDouble[4521.3246] Are both objects 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.