概念:抽象類Number
是表示數字值可轉換爲基本數據類型平臺類的超類byte
, double
, float
, int
, long
和short
。
常用方法:byteValue()、shortValue()、doubleValue()、floatValue()、intValue()、longValue()
轉換可能會丟失有關數值的總體大小的信息,可能會失去精度,甚至可能會返回與輸入不同的符號結果。涉及四捨五入。
已知直接子類:
包裝類 Byte , Double ,Float , Integer , Long , Short
AtomicInteger,AtomicLong ,
BigDecimal , BigInteger ,
DoubleAccumulator , DoubleAdder ,
LongAccumulator , LongAdder
包裝類(java.lang.x)
1.概念:Number抽象類的子類
2.作用:基本類型 int、long、double、float、boolean,使用在於效率,然而很多時候需要操縱的是對象,對象能攜帶更多信息,我們需要使用Integer、Long、Double、Float、Boolean等類打包成對象來操作。這些所謂的類即打包器(Wrapper)目的就是提供對象實例作爲“殼”。
3.構造方法:
Float (double value) 以double類型的參數value創建一個對象
Float (float value) 以float類型的參數value創建一個對象
Float (String s) 以String類型的參數s創建一個對象
4.方法:
compareTo(Float anotherF) 比較兩個對象的大小,大於返回1,相等返回0,小於返回-1
doubleValue() 以double數據類型返回double值,其他同理;