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-2025 CODEPRJ.COM