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.

ReturnMethodSummary
bytebyteValue()Returns the value of this Byte as a byte.
doubledoubleValue()Returns the value of this Byte as a double.
floatfloatValue()Returns the value of this Byte as a float.
intintValue()Returns the value of this Byte as an int.
longlongValue()Returns the value of this Byte as a long.
shortshortValue()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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.