Map<String,List<String>>转 Map<String,String>
时间: 2023-12-17 22:28:08 浏览: 96
map.toString()后转换成Map类型
4星 · 用户满意度95%
可以通过遍历Map<String,List<String>>,将List<String>转化为String,然后将其放入新的Map<String,String>中。具体实现如下所示:
```java
Map<String, List<String>> map1 = new HashMap<>();
Map<String, String> map2 = new HashMap<>();
for (Map.Entry<String, List<String>> entry : map1.entrySet()) {
String key = entry.getKey();
List<String> valueList = entry.getValue();
StringBuilder sb = new StringBuilder();
for (String value : valueList) {
sb.append(value);
}
map2.put(key, sb.toString());
}
```
阅读全文