java中String,int,Integer,char、double类型转换


转自 http://blog.csdn.net/zhang103886108/article/details/42917693

1、如何将字串 String 转换成整数 int? 
int i = Integer.valueOf(my_str).intValue();

int i=Integer.parseInt(str);

2、如何将字串 String 转换成Integer ?
Integer integer=Integer.valueOf(str);

 

3、如何将整数 int 转换成字串 String ? 
1.) String s = String.valueOf(i);
2.) String s = Integer.toString(i); 
3.) String s = "" + i; 

  4、如何将整数 int 转换成Integer ? 
Integer integer=new Integer(i);

6、如何将Integer 转换成 int ? 
int num=Integer.intValue();

12、String转double

String s;

double ss=Double.parseDouble(s);

 

注:parseDouble parseInt 返回的是double。

 

Double 和 Integer 是double和int的封装类 当需要转换成string类型的时候 需要用到。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2024 CODEPRJ.COM