Easy Tutorial
❮ Java Hashmap Get Collection Remove ❯

Java equals() Method

Java Number Class


The equals() method is used to determine if a Number object is equal to the method's parameter.

Syntax

public boolean equals(Object o)

Parameters

o -- Any object.

Return Value

Returns True if the Number object is not Null and is equal in both type and value to the method's parameter; otherwise, returns False.

Double and Float objects have some additional conditions, which can be referred to in the API manual: JDK 1.6.

Example

public class Test{
        public static void main(String args[]){
                Integer x = 5;
                Integer y = 10;
                Integer z = 5;
                Short a = 5;

                System.out.println(x.equals(y));  
                System.out.println(x.equals(z)); 
                System.out.println(x.equals(a));
        }
}

Compiling the above program will output:

false
true
false

Java Number Class

❮ Java Hashmap Get Collection Remove ❯