Suppose that I have a map of a set of strings to an integer value:
Map<HashSet<String>, Integer> map = new HashMap<>()
.
For example, the map
is (we assume no duplicate strings):
{x,y} -> 2
{z} -> 3
{u,v,w} -> 4
How can I get another_map
of type Map<String, Integer>
as follows, using Java 8 Stream APIs:
x -> 2
y -> 2
z -> 3
u -> 4
v -> 4
w -> 4
It looks like a flatMap
operation, but how could I associate the Integer values with each String key appropriately?