map<String,String> 转list
时间: 2023-10-17 12:58:52 浏览: 89
您可以使用Java的Stream API来将Map<String, String>转换为List。
使用Java 8及以上版本,您可以使用以下代码将Map的键转换为List:
List<String> result = map.keySet().stream()
.collect(Collectors.toList());
同样,您可以将Map的值转换为List:
List<String> result2 = map.values().stream()
.collect(Collectors.toList());
如果您想要对值进行过滤,可以使用filter方法:
List<String> result3 = map.values().stream()
.filter(x -> !"apple".equalsIgnoreCase(x))
.collect(Collectors.toList());
如果您希望将Map的键和值分别转换为两个独立的List,可以使用以下代码:
List<String> keys = new ArrayList<>(map.keySet());
List<String> values = new ArrayList<>(map.values());
希望这些代码可以帮助到您!<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [将Map<String,List<String>>转换为List<Map<String, String>>](https://blog.csdn.net/weixin_41799224/article/details/121380975)[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* [将Map转换为List](https://blog.csdn.net/m0_37598340/article/details/103080307)[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 ]
阅读全文