Java中各類數字類型轉換成字符串型:
String s = String.valueOf( value); // 其中 value 爲任意一種數字類型。
字符串型轉換成各類數字類型:
String str = "120";
byte b = Byte.parseByte( str );
short t = Short.parseShort( str );
int i = Integer.parseInt( str );
long l = Long.parseLong( str );
Float f = Float.parseFloat( str );
Double d = Double.parseDouble( str ); 對象
數字類型與數字類對象之間的轉換: 字符串
byte b = 120;
Byte bo = new Byte( b );
b = bo.byteValue(); io
short t = 120;
Short to = new Short( t );
t = to.shortValue(); float
int i = 169;
b = bo.byteValue(); 類型轉換
short t = 169;
Short to = new Short( t );
t = to.shortValue(); 字符
int i = 169;
Integer io = new Integer( i );
i = io.intValue(); 數字
long l = 169;
Long lo = new Long( l );
l = lo.longValue(); new
float f = 169f;
Float fo = new Float( f );
f = fo.floatValue();
double d = 169f; Double dObj = new Double( d ); d = dObj.doubleValue();