JAVA中int,string,char之间的互相转换

来源:互联网 发布:搜图神器软件 编辑:程序博客网 时间:2024/05/22 06:36

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

原创粉丝点击