Create an Integer object in Java


To create an Integer object in Java is quite easy. Let us learn about the following two ways for this purpose.

Method1

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      Integer obj = new Integer("199");
      System.out.println(obj);
   }
}

Output

199

Method2 −Now let us see the second way

Example

Public class Demo {
   public static void main(String []args) {
      Integer obj = new Integer(99);
      System.out.println(obj);
   }
}

Output

99

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Jun-2020

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements