Java xxxValue() 方法
xxxValue() 方法用于將 Number 對象轉(zhuǎn)換為 xxx 數(shù)據(jù)類型的值并返回。
相關(guān)的方法有:
類型 | 方法及描述 |
---|---|
byte | byteValue() : 以 byte 形式返回指定的數(shù)值。 |
abstract double | doubleValue() : 以 double 形式返回指定的數(shù)值。 |
abstract float | floatValue() : 以 float 形式返回指定的數(shù)值。 |
abstract int | intValue() : 以 int 形式返回指定的數(shù)值。 |
abstract long | longValue() : 以 long 形式返回指定的數(shù)值。 |
short | shortValue() : 以 short 形式返回指定的數(shù)值。 |
參數(shù)
以上各函數(shù)不接受任何的參數(shù)。
返回值
轉(zhuǎn)換為 xxx 類型后該對象表示的數(shù)值。
實例
public class Test{ public static void main(String args[]){ Integer x = 5; // 返回 byte 原生數(shù)據(jù)類型 System.out.println( x.byteValue() ); // 返回 double 原生數(shù)據(jù)類型 System.out.println(x.doubleValue()); // 返回 long 原生數(shù)據(jù)類型 System.out.println( x.longValue() ); } }
編譯以上程序,輸出結(jié)果為:
5 5.0 5
更多建議: