Skip to content

Convert Short object to numeric primitive types Example

This example shows how to convert Short object to numeric primitive types byte, short, int, long, float, and double.

How to convert Short object to numeric primitive types in Java?

Use the xxxValue method of Short wrapper class to convert a Short object to the primitive numeric types where the xxx is a primitive type you want to convert to as given below.

1) Convert Short to byte

Use the byteValue method of the Short wrapper class to convert from Short to byte primitive value.

This method returns the value of the Short object as a byte primitive.

2) Convert Short to short

Use the shortValue method of the Short wrapper class to convert from Short to short primitive value.

This method returns the value of the Short object as a short primitive.

3) Convert Short to int

Use the intValue method of the Short wrapper class to convert from Short to int primitive value.

This method returns the value of the Short object as an int primitive.

4) Convert Short to long

Use the longValue method of the Short wrapper class to convert from Short to a long primitive value.

This method returns the value of the Short object as long primitive.

5) Convert Short to float

Use the floatValue method of the Short wrapper class to convert from Short to a float primitive value.

This method returns the value of the Short object as float primitive.

6) Convert Short to double

Use the doubleValue method of the Short wrapper class to convert from Short to double primitive value.

This method returns the value of the Short object as a double primitive.

Example

Output

This example is a part of the Java Basic Examples and Java Type conversion Tutorial.

Please let me know your views in the comments section below.

About the author

Leave a Reply

Your email address will not be published.