Java xxxValue() method
xxxValue() method is used to convert the Number object into a value of xxx data type and return.
Relevant methods are:
Type | Method and description |
---|---|
byte | byteValue() : Returns the specified value in byte form. |
abstract double | doubleValue() : Returns the specified value in double form. |
abstract float | floatValue() : Returns the specified value in float form. |
abstract int | intValue() : Returns the specified value in int form. |
abstract long | longValue() : Returns the specified value in long form. |
short | shortValue() : Returns the specified value in short form. |
Parameters
The above functions do not accept any parameters.
Return value
The numerical value represented by the object after being converted to the xxx type.
Example
public class Test{ public static void main(String args[]){ Integer x = 5; // 返回 byte 原生数据类型 System.out.println( x.byteValue() ); // 返回 double 原生数据类型 System.out.println(x.doubleValue()); // 返回 long 原生数据类型 System.out.println( x.longValue() ); }}
Compile the above program and the output result is:
55.05