Java Basic Examples

Convert Integer object to numeric primitive types Example

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

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

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

1) Convert Integer to byte

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

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

2) Convert Integer to short

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

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

3) Convert Integer to int

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

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

4) Convert Integer to long

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

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

5) Convert Integer to float

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

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

6) Convert Integer to double

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

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