Convert short primitive type to Short object in Java


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

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

368 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements