Create Integer using its constructors

ConstructorSummary
Integer(int value)Creates an Integer object for the int value.
Integer(String s)Creates an Integer object for the int value indicated by s.

public class Main {
  public static void main(String[] args) {

    Integer integer1 = new Integer("1");
    Integer integer2 = new Integer("2");
    
    System.out.println(integer1);
    System.out.println(integer2);
  }
}

The output:


1
2

Create Integer objects from int literal and string representation


public class Main {
  public static void main(String[] args) {
    Integer intObj1 = new Integer(10);
    Integer intObj2 = new Integer("10");
    System.out.println(intObj1);
    System.out.println(intObj2);
  }
}

The output:


10
10
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.