I have a map like bellow,
[key = "car", value = ["bmw", "toyota"]]
[key = "bike", value = ["honda", "kawasaki"]]
I want to convert it to another map using java 8 functional apis like bellow,
[key = "bmw", value = "car"]
[key = "toyota", value = "car"]
[key = "honda", value = "bike"]
[key = "kawasaki", value = "bike"]
for(String k: map.keySet()) for(String key: map.get(k)) result.put(key, k);, but in either case, it’s doing an unnecessary lookup on the map it’s iterating over, sofor(Map.Entry<String,List<String>> e: map.entrySet()) for(String key: e.getValue()) result.put(key, e.getKey());is preferable…