JAVA中int,string,char之間的互相轉換

(1) 字符串string轉int:

int i=Integer.parseInt(str);//使用Integer.parseInt(String str)函數,返回str所代表的int值;

(2) 如何將字串 String 轉換成Integer
Integer integer=Integer.valueOf(str);//string轉Integer對象

(3) 將整數 int 轉換成字串 String
1.) String s = String.valueOf(i);//使用String.valueOf(int i);返回String

2.) String s = Integer.toString(i); //使用Integer.toString()

3.) String s = “” + i; //比較low的一種方式

(4) 將整數 int 轉換成Integer
Integer integer=new Integer(i);

(5) 將Integer 轉換成字串 String
Integer integer=String

(6) 將Integer 轉換成 int
int num=Integer.intValue();

(7) 將String轉換成 BigDecimal
BigDecimal d_id = new BigDecimal(str);

(8) 將 String 轉換成 char
char[] ca=”123”.toCharArray();

(9) 將char轉換成String
String s=ca.toString(); //任何類型都可以採用toString()轉換成String類型

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章