Convert short primitive type to Short object in Java

Java 8Object Oriented ProgrammingProgramming

Let us first create a short primitive type and assign a value.

short val = 30;

Now, create a Short object and set the above short type to it.

Short myShort = new Short(val);

The following is the complete example to convert short primitive type to Short object using Short constructor.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      short val = 30;
      Short myShort = new Short(val);
      System.out.println(myShort);
   }
}

Output

30
raja
Published on 12-Nov-2018 17:02:07
Advertisements