Convert Byte to byte, double, float, int, long and short

The following table shows the methods we can use to convert a Byte object to primitive byte value, double value, float value, int value, long value and short value.

byte byteValue()
Returns the value of this Byte as a byte.
double doubleValue()
Returns the value of this Byte as a double.
float floatValue()
Returns the value of this Byte as a float.
int intValue()
Returns the value of this Byte as an int.
long longValue()
Returns the value of this Byte as a long.
short shortValue()
Returns the value of this Byte as a short.

public class Main {
  public static void main(String[] args) {
    Byte byteObject = new Byte("10");
    byte b = byteObject.byteValue();
    System.out.println("byte:"+b);

    short s = byteObject.shortValue();
    System.out.println("short:"+s);

    int i = byteObject.intValue();
    System.out.println("int:"+i);

    float f = byteObject.floatValue();
    System.out.println("float"+f);

    double d = byteObject.doubleValue();
    System.out.println("double:"+d);

    long l = byteObject.longValue();
    System.out.println("long:"+l);
  }
}

The output:


byte:10
short:10
int:10
float10.0
double:10.0
long:10
Home 
  Java Book 
    Essential Classes  

Byte:
  1. Byte
  2. Find out byte's max value, min value and size
  3. Create Byte object with its constructor
  4. Convert Byte to byte, double, float, int, long and short
  5. Decode a string to a byte
  6. Byte class defines static methods to convert string value to byte value
  7. Convert byte value to string value
  8. Compare two byte values