list元素逗号隔开
时间: 2023-09-13 10:07:19 浏览: 125
要将一个List元素用逗号隔开可以使用Java 8的Stream流来实现。你可以使用Stream的collect方法结合Collectors.joining方法,将List中的元素连接成一个字符串。具体实现如下:
```
List<String> list = new ArrayList<>();
list.add("a");
list.add("b");
list.add("c");
list.add("d");
String str = list.stream().collect(Collectors.joining(","));
System.out.println(str);
```
输出结果为:a,b,c,d。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [java List数组用逗号分隔开,转成字符串](https://blog.csdn.net/weixin_45042272/article/details/130220003)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [数组常用操作。以逗号隔开、以逗号+单引号隔开、转List等](https://blog.csdn.net/programmer_sir/article/details/102582202)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文