What is the idiomatic way to map a Collection<Foo>
onto a MultiMap<A, B>
? Were
public class Foo {
public A key;
public B val;
}
(This is simplified, of course.)
The way I can think to do it is to to use Collection::stream()
to invoke MultiMap::put
on each element, but I feel there might be a much more elegant way to do this.
And can a new MultiMap
be returned with those mappings, all in one line?