Create an Integer object in Java

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 13-Nov-2018 05:10:46
Advertisements