字符串数组转list
时间: 2023-08-26 09:13:31 浏览: 100
python如何把字符串类型list转换成list
要将字符串数组转换为List集合,可以使用Arrays.asList()方法。该方法将数组转换为List的视图,可以查看和修改List中的元素。以下是几种常见的方法:
方法一:
```
String[] strArray = {"apple", "banana", "orange"};
List<String> list = Arrays.asList(strArray);
```
方法二:
```
String[] strArray = {"apple", "banana", "orange"};
List<String> list = new ArrayList<>(Arrays.asList(strArray));
```
方法三:
```
String[] strArray = {"apple", "banana", "orange"};
List<String> list = new ArrayList<>();
Collections.addAll(list, strArray);
```
需要注意的是,使用Arrays.asList()方法得到的List是固定长度的,不支持增删操作,只能对元素进行查改。如果需要对List进行增删操作,可以使用方法二或方法三将数组转换为ArrayList。<em>1</em><em>2</em><em>3</em>
#### 引用[.reference_title]
- *1* [字符数组转list集合](https://blog.csdn.net/jinanmao/article/details/109533106)[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^chatsearchT3_1"}} ] [.reference_item]
- *2* [字符串数组转成list的三种方案](https://blog.csdn.net/Gaily1/article/details/81262270)[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^chatsearchT3_1"}} ] [.reference_item]
- *3* [将字符串数组String[]转换成List的三种方法](https://blog.csdn.net/weixin_45815061/article/details/125143992)[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^chatsearchT3_1"}} ] [.reference_item]
[ .reference_list ]
阅读全文