三种方法
1.a+"";
2.String.valueOf(a);
2.Integer.toString(a);
//定义变量 int a = 1002; //int转为String //第一种方法 String s1 = a + ""; //第二种方法 String s2 = String.valueOf(a); //第三种方法 String s3 = Integer.toString(a); //输出 System.out.println(s1); System.out.println(s2); System.out.println(s3); //输出结果 1002 1002 1002String转为int
两种方法
1.Integer.valueOf(b).intValue();
2.Integer.parseInt(b);
//定义变量
String b = "1002";
//String转为int
//第一种方法
int b1 = Integer.valueOf(b).intValue();
//第二种方法
int b2 = Integer.parseInt(b);
//输出
System.out.println(b1);
System.out.println(b2);
//输出结果
1002
1002
Integer转为String
两种方法
1.Integer.toString(f);
2.String.valueOf(f);
//定义变量
Integer f = 1002;
//Integer转为String
//第一种方法
String f1 = Integer.toString(f);
//第二种方法
String f2 = String.valueOf(f);
//输出
System.out.println(f1);
System.out.println(f2);
//输出结果
1002
1002
String转为Integer
一种方法
1.Integer.valueOf(d);
//定义变量
String d = "1002";
//String转为Integer
Integer d1 = Integer.valueOf(d);
//输出
System.out.println(d1);
//输出结果
1002
int转为Integer
一种方法
1.new Integer(g);
//定义变量
int g = 1002;
//int转为Integer
Integer g1 = new Integer(g);
//输出
System.out.println(g1);
//输出结果
1002
Integer转为int
一种方法
1.h.intValue();
//定义变量
Integer h = 1002;
//Integer转为int
int h1 = h.intValue();
//输出
System.out.println(h1);
//输出结果
1002



