String 转int:
int x=Integer.parseInt("5");
//注意parseInt里面的参数
必须是个没有小数点的数(不能是double形式的),不然运行时会抛出异常
NumberFormatException
String 转double:
double d=Double.parseDouble("25.23542");
//注意参数一定要有小数点。。不然运行时会抛出异常 NumberFormatException
String转boolean
boolean b=new Boolean("true").booleanValue();
//这个实验的结果很奇怪,只有参数是"true"的时候会返回true,其他时候都返回false(包括"1","0"的时候都返回false)
double转String:
String str=Double.toString(2)//结果显示2.0,不像上面会报错
String str=Double.toString(2.545)
int转String类似
boolean转String:
以上parseInt等皆为
静态方法,详见:
http://blog.163.com/it_novice/blog/static/209183069201331584937375/