Java Integer equals() Method

The equals() method is a method of Integer class under java.lang package. This method compares the value of the parameter to the value of the current Integer object. It returns Boolean (True or False) which corresponds to the equality of this Integer and method argument object. It also overrides the equals() method of Object class.

Syntax:

Following is the declaration of equals() method:

Parameter:

DataTypeParameterDescriptionRequired/Optional
ObjectobjIt checks the equality with the specified IntegerRequired

Returns:

The equals() method will return true if the argument is not null and if the integer objects are the same as method argument object, otherwise it will return false.

Exceptions:

InputMismatchException

Compatibility Version:

Java 1.2 and above

Example 1

Output:

obj1 and obj2 are equal. True or False? = false
obj1 and obj2 are equal. True or false? = true

Example 2

Output:

1.	Input the first Integer Number to be Compare: 34
Input the second Integer Number to be Compare: 34
Both the Integer numbers are same...

2.	Input the first Integer Number to be Compare: 45
Input the second Integer Number to be Compare: 87
Both the Integer numbers are different...

Example 3

Output:

objA == objB? true
objB == objC? false
objA == objC? false
objC == objA? false
objB == objA? true

Example 4

Output:

ObjFloat == ObjDouble? false