Short wrapper class is used to wrap primitive data type short value in an object.
Examples of Short Wrapper Class
Example 1 : Convert short data type to Short object
public class shortToShort
{
public static void main(String[] args)
{
short s = 1;
Short sObj = new Short(s);
System.out.println(sObj);
}
}
Output
1
This example shows how a short data type value can be converted to short object.
Example 2 : Convert String to Short object
public class StringToShort
{
public static void main(String[] args)
{
Short s1 = new Short("1");
System.out.println(s1);
String str = "2";
Short s2 = Short.valueOf(str);
System.out.println(s2);
}
}
Output
1
2
This example shows how we can convert String object to Short object.