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.
Return | Method | Summary |
---|---|---|
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
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. |