Convert Long object to numeric primitive types Example

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

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

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

1) Convert Long to byte

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

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

2) Convert Long to short

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

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

3) Convert Long to int

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

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

4) Convert Long to long

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

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

5) Convert Long to float

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

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

6) Convert Long to double

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

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

RahimV

RahimV

My name is RahimV and I have over 16 years of experience in designing and developing Java applications. Over the years I have worked with many fortune 500 companies as an eCommerce Architect. My goal is to provide high quality but simple to understand Java tutorials and examples for free. If you like my website, follow me on Facebook and Twitter.

Add Comment

Your email address will not be published. Required fields are marked *