In this example, let’s see how to convert an Integer object into below given numeric data types – Convert Integer to byte – Convert Integer to short – Convert Integer to int – Convert Integer to float – Convert Integer to double.
Source Code
package com.beginner.examples;
public class ConvertIntegerExample {
public static void main(String[] args) {
Integer integer = new Integer(20);
//Convert to byte type
byte toByte = integer.byteValue();
//Convert to short type
short toShort = integer.shortValue();
//Convert to float type
float toFloat = integer.floatValue();
//Convert to Double type
double toDouble = integer.doubleValue();
System.out.println("Byte:"+toByte);
System.out.println("Short:"+toShort);
System.out.println("Int:"+integer);
System.out.println("Float:"+toFloat);
System.out.println("Double:"+toDouble);
}
}
Output:
Byte:20
Short:20
Int:20
Float:20.0
Double:20.0