java中int和String类型的相互转换

来源:互联网 发布:深夜解莫软件 编辑:程序博客网 时间:2024/06/06 23:52

int转换为string

int number = 100;// 方式1String s1 = "" + number;// 方式2(推荐)String s2 = String.valueOf(number);// 方式3:int -- Integer -- StringInteger i = new Integer(number);String s3 = i.toString();// 方式4String s4 = Integer.toString(number);

string转换为int

String s = "100";// 方式1:String -- Integer -- intInteger ii = new Integer(s);int x = ii.intValue();//方式2int y = Integer.parseInt(s);
0 0