OptionalDouble equals() method in Java with examples Last Updated : 01 May, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 ==. Syntax: 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: Program 1: Java // Java program to demonstrate // OptionalDouble.equals(Object obj) method import java.util.OptionalDouble; public class GFG { public static void main(String[] args) { // Create first OptionalDouble object OptionalDouble opDouble1 = OptionalDouble.of(452.13246); System.out.println("OptionalDouble 1: " + opDouble1.toString()); // Create second OptionalDouble object OptionalDouble opDouble2 = OptionalDouble.of(452.13246); System.out.println("OptionalDouble 2: " + opDouble2.toString()); // Check if these two objects are equal // using equals(Object obj) System.out.println("Are both objects equal: " + opDouble1.equals(opDouble2)); } } Output: OptionalDouble 1: OptionalDouble[452.13246] OptionalDouble 2: OptionalDouble[452.13246] Are both objects equal: true Program 2: Java // Java program to demonstrate // OptionalDouble.equals(Object obj) method import java.util.OptionalDouble; public class GFG { public static void main(String[] args) { // Create first OptionalDouble object OptionalDouble opDouble1 = OptionalDouble.of(3179464.92); System.out.println("OptionalDouble 1: " + opDouble1.toString()); // Create second OptionalDouble object OptionalDouble opDouble2 = OptionalDouble.of(4521.3246); System.out.println("OptionalDouble 2: " + opDouble2.toString()); // Check if these two objects are equal // using equals(Object obj) System.out.println("Are both objects equal: " + opDouble1.equals(opDouble2)); } } Output: OptionalDouble 1: OptionalDouble[3179464.92] OptionalDouble 2: OptionalDouble[4521.3246] Are both objects equal: false References: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalDouble.html#equals?(Object obj) Comment More infoAdvertise with us Next Article OptionalLong equals() method in Java with examples A AmanSingh2210 Follow Improve Article Tags : Java Java - util package Java-Functions Java-OptionalDouble Practice Tags : Java Similar Reads Optional equals() method in Java with Examples The equals() method of java.util.Optional class in Java is used to check for equality of this Optional with the specified Optional. This method takes an Optional instance and compares it with this Optional and returns a boolean value representing the same. Syntax: public boolean equals(Object obj) P 2 min read Optional equals() method in Java with Examples The equals() method of java.util.Optional class in Java is used to check for equality of this Optional with the specified Optional. This method takes an Optional instance and compares it with this Optional and returns a boolean value representing the same. Syntax: public boolean equals(Object obj) P 2 min read OptionalLong equals() method in Java with examples OptionalLong help us to create an object which may or may not contain a Long value. The equals(Object obj) method help us to compare this OptionalLong object with the passed object as a parameter and it returns true if objects are equal. The other object is considered equal to this OptionalLong if: 2 min read OptionalInt equals() method in Java with examples OptionalInt help us to create an object which may or may not contain a Int value. The equals(Object obj) method help us to compare this OptionalInt object with the passed object as a parameter and it returns true if objects are equal. The other object is considered equal to this OptionalInt if: it i 2 min read Properties equals(value) method in Java with Examples The equals(value) method of Properties class is used to check for equality between two properties. It verifies whether the elements of one properties object passed as a parameter is equal to the elements of this properties or not. Syntax: public boolean equals(Object value) Parameters: This method a 2 min read Properties equals(value) method in Java with Examples The equals(value) method of Properties class is used to check for equality between two properties. It verifies whether the elements of one properties object passed as a parameter is equal to the elements of this properties or not. Syntax: public boolean equals(Object value) Parameters: This method a 2 min read Like