2 回答

TA贡献1845条经验 获得超8个赞
Map<String, List<String>> newMap = new HashMap<>();
for (Map.Entry<String, String> entry : masterList.entrySet()) {
List<String> values = new LinkedList<>();
if (entry.getKey().startsWith("tag_")) {
String[] words = entry.getValue().split(",\\s*");
Collections.addAll(values, words);
} else {
values.add(entry.getValue());
}
newMap.put(entry.getKey(), values);
}
一个不应该改变地图的类型,所以需要创建一个新的地图。

TA贡献1860条经验 获得超9个赞
if (entry.getKey().startsWith("tag_")) {
ArrayList < String > list = new ArrayList();
tagDataList = Arrays.asList(entry.getValue().toString().split(","));
for (String string: tagDataList) {
list.add(string);
}
tagsMap.put(entry.getKey(), list);
}
添加回答
举报