逗号隔开的转list
时间: 2023-10-12 19:06:29 浏览: 91
Python实现按逗号分隔列表的方法
要将逗号分隔的字符串转为列表,有几种方法可以实现。根据提供的引用内容,我可以给出以下几种方法:
1. 使用split方法:可以使用split方法将逗号分隔的字符串拆分为数组,然后将数组中的元素逐个添加到列表中。例如,在Java中可以这样实现:
```java
String string = "1,2,3";
String[] split = string.split(",");
List<String> list = new ArrayList<>();
for (String str : split) {
list.add(str);
}
System.out.println(list);
```
输出结果为:。。。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [将以逗号隔开string字符串,转为list](https://blog.csdn.net/qq_45343541/article/details/127532455)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [字符串以逗号分隔的转换为List或数组方法](https://blog.csdn.net/m0_37914467/article/details/110821277)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文