Convert Short to primitive types
In this chapter you will learn:
Convert Short to byte, double, float, int, long and short
The following list have the methods which we can use to convert short value.
byte byteValue()
returns the value of this Short as a byte.double doubleValue()
returns the value of this Short as a double.float floatValue()
returns the value of this Short as a float.int intValue()
returns the value of this Short as an int.long longValue()
returns the value of this Short as a long.short shortValue()
returns the value of this Short as a short.
public class Main {
public static void main(String[] args) {
Short shortObject = new Short("10");
byte b = shortObject.byteValue();
System.out.println("byte:"+b);
/* ja va 2 s . co m*/
short s = shortObject.shortValue();
System.out.println("short:"+s);
int i = shortObject.intValue();
System.out.println("int:"+i);
float f = shortObject.floatValue();
System.out.println("float"+f);
double d = shortObject.doubleValue();
System.out.println("double:"+d);
long l = shortObject.longValue();
System.out.println("long:"+l);
}
}
The output:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Primitive Data Types