Convert Byte to byte, double, float, int, long and short
In this chapter you will learn:
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.
Method Name | Description |
---|---|
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. |
The following code demonstrates the methods listed above.
public class Main {
public static void main(String[] args) {
Byte byteObject = new Byte("10");
byte b = byteObject.byteValue();
System.out.println("byte:"+b);
/*ja va 2s. co m*/
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:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Primitive Data Types