1:字符数组转换为字符串
public class TestChange{
public static void main(String[] args) {
char[] c = ['c', 'h', 'a', 'r'];
String str = String.copyValueOf(c);
System.out.println(str + "Type: " + str.getClass().getTypeName());
}
}
2: 字符串转换为字符数组
public class TestType{
public static void main(String[] args) {
String str = "String";
char[] ch = str.toCharArray();
System.out.println(ch);
}
}
3: String->Integer
public class TestType {
public static void main(String[] args) {
String str = "1234";
int i = Integer.parseInt(str);
System.out.println(i);
}
}
4: Number->String
public class TestType {
public static void main(String[] args) {
int i = 1234;
String str = String.valueOf(i);
System.out.println(str);
}
}