Java Integer equals() MethodThe 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:
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 1Output: obj1 and obj2 are equal. True or False? = false obj1 and obj2 are equal. True or false? = true Example 2Output: 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 3Output: objA == objB? true objB == objC? false objA == objC? false objC == objA? false objB == objA? true Example 4Output: ObjFloat == ObjDouble? false Next TopicJava-integer-floatvalue-method |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India