Java Data Type Tutorial - Java Integer.equals(Object obj)








Syntax

Integer.equals(Object obj) has the following syntax.

public boolean equals(Object obj)

Example

In the following code shows how to use Integer.equals(Object obj) method.

public class Main {
// w w w  .j a  v  a  2  s  . c  om
   public static void main(String[] args) {

     Integer obj1 = new Integer(5);
     Integer obj2 = new Integer(5);
     System.out.println(obj1.equals(obj2));
    
     obj1 = new Integer(3);
     obj2 = new Integer(2);
     System.out.println(obj1.equals(obj2));
   }
} 

The code above generates the following result.