java中JDK1.7将LIst里面的值拼接成字符串
时间: 2024-01-29 19:02:13 浏览: 132
在JDK1.7中,可以使用StringBuilder来将List里面的值拼接成一个字符串,每个元素之间用逗号分隔。代码如下:
```
List<String> list = Arrays.asList("apple", "banana", "orange");
StringBuilder sb = new StringBuilder();
for (String s : list) {
if (sb.length() > 0) {
sb.append(",");
}
sb.append(s);
}
String result = sb.toString();
System.out.println(result);
```
输出结果为:
```
apple,banana,orange
```
阅读全文