I'm pretty new to Java 8 and I have the following requirement to convert:
Map<Shape, int[]> --> Map<Shape, Set<Integer>>
Any ideas?
I've edited the question in hope that a Set<Integer>
is what you really need, cause you can't have a primitive Set
of type Set<int>
.
map.entrySet()
.stream()
.collect(Collectors.toMap(
Entry::getKey,
x -> Arrays.stream(x.getValue()).boxed().collect(Collectors.toSet())
));
On the other hand if you really want unique primitives, then a distinct
and toArray
will work, but the type is still going to be Map<Shape, int[]>
:
map.entrySet()
.stream()
.collect(Collectors.toMap(
Entry::getKey,
x -> Arrays.stream(x.getValue()).distinct().toArray()
));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With