Shv*_*alb 4 java dictionary set java-8
我是Java 8的新手,我有以下要求转换:
Map<Shape, int[]> --> Map<Shape, Set<Integer>>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我已经编辑在希望的问题,一个Set<Integer>是你真正需要的,因为你不能有一个原始Set类型Set<int>.
map.entrySet()
.stream()
.collect(Collectors.toMap(
Entry::getKey,
x -> Arrays.stream(x.getValue()).boxed().collect(Collectors.toSet())
));
Run Code Online (Sandbox Code Playgroud)
另一方面,如果你真的想要独特的原语,那么a distinct和toArray将会工作,但类型仍然是Map<Shape, int[]>:
map.entrySet()
.stream()
.collect(Collectors.toMap(
Entry::getKey,
x -> Arrays.stream(x.getValue()).distinct().toArray()
));
Run Code Online (Sandbox Code Playgroud)