It\'s a simple question, I have a simple HashMap of which i want to reverse the keys and values.
HashMap myHashMap = new HashMap<
If the values are not unique, the safe way to inverse the map is by using java 8's groupingBy function
Map map = new HashMap<>();
map.put("a",1);
map.put("b",2);
Map> mapInversed =
map.entrySet()
.stream()
.collect(Collectors.groupingBy(Map.Entry::getValue, Collectors.mapping(Map.Entry::getKey, Collectors.toList())))