Java內數字的表示

除了基本的primitive type: byte, short, int, long, float, double外

還有wrap class: Byte, Short, Integer, Long, Float, Souble

處理大整數用的BigInteger和BigDecimal

和在Thread用的:AtomicInteger和AtomicLong

 

1. 官網https://docs.oracle.com/javase/tutorial/java/data/numberclasses.html

下圖是說數字方面的wrap class都是由Number這class衍生出來的

01.png

 

2.  數字在使用時能用primitive type則優先使用

而哪時候需要用wrap class的內容呢?

主要有3個時機點

a. method的輸入參數需要用object類型時

b. 要使用或取得數字的定義, 像是MIN_VALUE和MAX_VALUE

c. 將數字轉成其他primitive type或是string的時候

02.png  

arrow
arrow

    RX1226 發表在 痞客邦 留言(0) 人氣()