您的位置:首页 > 编程语言 > Java开发

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

2018-03-12 20:44 609 查看
(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类型
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: