Create Integer object - Java Language Basics

Java examples for Language Basics:int

Description

Create Integer object

Demo Code

 
public class Main {
 
  public static void main(String[] args) {
    //1. Create an Integer object from int
    Integer intObj1 = new Integer(10);
   //from   ww  w.ja  v  a2  s .  c  o  m
    /*
    2. Create and Integer object from String. 
    */
    Integer intObj2 = new Integer("10");
   
    //print value of Integer objects
    System.out.println(intObj1);
    System.out.println(intObj2);
  }
}

Result


Related Tutorials