关于类型转化问题:
(1)String---------》char / char[ ]
String str = "ab"; char str1 = str.charAt(0); //得到a char str2 = str.charAt(1); //得到b char[ ] str3 = str.toCharArray(); System.out.println (Arrays.toString(str3));
(2)char / char[]-----------》String
char m = ‘a‘; String str = String.valueOf(m); String str2 = m + " "; char[] m = {‘a‘,‘b‘}; String str3 = String.copyValueOf(m); String str4 = new String(m);
(3)int -----------》 String
int i; String s = String.valueOf(i); String s = Integer.toString(i); String s = "" + i;
(4)String ----------》 int
注意: Integer.parseInt(s)转换的只能是数字字符串
String s = "1"; int i = Integer.parseInt(s); String str = "123"; i = Integer.parseInt(str,10); i = Integer.valueOf(s).intValue()