1.字符串转换成各种数字
String s = "1";
byte b = Byte.parseByte( s );
short t = Short.parseShort( s );
int i = Integer.parseInt( s );
long l = Long.parseLong( s );
Float f = Float.parseFloat( s );
Double d = Double.parseDouble( s );
2.各种数字转换成字符串
String s=String.valueOf(value);
其中value即待转换的数字类型。
3.数字类与数字包装类之间的转换(以int \double为例)
int i = 1;
Integer temp = new Integer( i );
i = temp.intValue();
double d = 1f;
Double temp= new Double( d );
d = temp.doubleValue();
本文介绍了如何在Java中将字符串转换为各种数字类型,如byte、short、int等,并演示了从数字到字符串及数字类与包装类间的转换方法。
119

被折叠的 条评论
为什么被折叠?



