Java equals() Method
The equals() method is used to determine whether the Number object is equal to the parameter of the method.
Syntax
public boolean equals(Object o)
Parameters
o-- any object.
Return Value
If the Number object is not Null, and its type and value are both equal to the method's parameter, it returns True; otherwise, it returns False.
Double and Float objects also have some additional conditions; refer to the API manual:JDK 1.6。
Example
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));
}
}
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));
}
}
Compile the above program, and the output result is:
false true false
Other Extensions
Java Number Class