1Map<String, ArrayList<Integer>> reverseMap = new HashMap<>();
2
3for (Map.Entry<Integer,String> entry : map.entrySet()) {
4 if (!reverseMap.containsKey(entry.getValue())) {
5 reverseMap.put(entry.getValue(), new ArrayList<>());
6 }
7 ArrayList<Integer> keys = reverseMap.get(entry.getValue());
8 keys.add(entry.getKey());
9 reverseMap.put(entry.getValue(), keys);
10}