java中如何将字符串数组转换成字符串(转)如果是 “字符串数组” 转 “字符串”,只能通过循环,没有其它⽅法
String[] str = {"abc", "bcd", "def"};
StringBuffer sb = new StringBuffer();
for(int i = 0; i < str.length; i++){
sb. append(str[i]);
}
String s = sb.toString();
如果是 “字符数组” 转 “字符串” 可以通过下边的⽅法
char[] data={'a','b','c'};
String s=new String(data);
//字符数组转List
String[] s = {"a","b","c"};
List list= java.util.Arrays.asList(s);
//List转字符数组——例⼦⼀
List<String> list = new ArrayList<String>();
java数组字符串转数组list.add("a1");
list.add("a2");
String[] toBeStored = Array(new String[list.size()]);
for(String s : toBeStored) {
System.out.println(s);
}
//List转字符数组——例⼦⼆
List<String> list = new ArrayList<String>();
list.add("a1");
list.add("a2");
String[] toBeStored = new String[al.size()];
for (String s : toBeStored) {
System.out.println(s);
}
//List转字符数组——例⼦三
List<String> list = new ArrayList<String>();
list.add("a1");
list.add("a2");
String[] toBeStored = new String[]{};
String[] str = al.toArray(toBeStored);
for (String s : str) {
System.out.println(s);
}
利⽤此转化:String str[] = Array(new String[]{});
List list= java.util.Arrays.asList(String str[]);
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论