至尊宝的传说
我重新创建了您的示例,这应该可以满足您的要求。如果对代码还有任何其他问题,请告诉我。HashMap<String,List<String>> hashMap = new HashMap<>(); hashMap.put("k1", Arrays.asList("v1","v2")); hashMap.put("k2", Arrays.asList("v2")); hashMap.put("k3", Arrays.asList("v1")); HashMap<String,List<String>> result = new HashMap<>(); hashMap.forEach((s, strings) ->{ for (String element : strings){ List<String> tempList = new ArrayList<>(); if(result.containsKey(element)){ tempList = result.get(element); } tempList.add(s); result.put(element, tempList); } });