字符串数组转字符串(只能通过for循环):
String[] str = {'a', 'b', 'd'};
StringBuffer sb = new StringBuffer();
for(int i = 0; i < str.length;i++){
sb.append(str[i]);
}
String s = sb.toString();
字符数组转字符串可以通过下面的方式:
char[] data = {'a', 'b', 'd'};
String s = new String(data);
字符串到字符数组:
String str = "123abc";
char[] ar = str.toCharArray(); //char数组
for(int i =0;i<ar.length;i++){
System.out.println(ar[i]); //1 2 3 a b c
}
String[] arr = str.split("");
for(int i =0;i<arr.length;i++){ //String数组,不过arr[0]为空
System.out.println(arr[i]); //空 1 2 3 a b c
}
整形到字符串:
String str = Integer.toString(i);
字符串到整形:
int i = Integer.valueOf(str).intValue();