Java Basic Examples

Convert Long object to numeric primitive types Example

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

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

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

1) Convert Long to byte

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

This method returns the value of the Long object as byte primitive.

2) Convert Long to short

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

This method returns the value of the Long object as short primitive.

3) Convert Long to int

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

This method returns the value of the Long object as int primitive.

4) Convert Long to long

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

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

5) Convert Long to float

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

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

6) Convert Long to double

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

This method returns the value of the Long object as double primitive.

Example

Output

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

 

Join 1000+ fellow learners! Enter your email address below: