Skip to content

Convert Byte object to numeric primitive types Example

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

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

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

1) Convert Byte to byte

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

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

2) Convert Byte to short

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

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

3) Convert Byte to int

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

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

4) Convert Byte to long

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

This method returns the value of the Byte object as a long primitive.

5) Convert Byte to float

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

This method returns the value of the Byte object as a float primitive.

6) Convert Byte to double

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

This method returns the value of the Byte 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.