Java类型转换-int-Integer-String
int与Integer
// int转Integer:
int a = 0;
Integer b = new Integer(a);
// 或
// Integer b = a;
// Integer转int:
Integer a = new Integer(0);
int b = a.intValue();
Integer与String
// Integer转String
Integer i = 123;
String string = i.toString();
String string2 = Integer.toString(i);
String string3 = String.valueOf(i);
// String转Integer
String str = "123";
Integer integer = Integer.valueOf(str);
int与String
// String转int
String s = "123";
int i1 = Integer.parseInt(s);
int i2 = Integer.valueOf(s).intValue();
// int转String
int i = 123;
String s1 = String.valueOf(i);
String s2 = Integer.toString(i);
String s3 = "" + i;
注:需注意类型转换时,字符串是否为空的判断,及类型转换异常(java.lang.ClassCastException)