Javatpoint Logo
Javatpoint Logo

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:

DataType Parameter Description Required/Optional
Object obj It checks the equality with the specified Integer Required

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

Test it Now

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

Test it Now

Output:

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

Example 4

Test it Now

Output:

ObjFloat == ObjDouble? false






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA