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类型

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