mah*_*aja 8 collections java-8
如何将Java8 IntStream收集到Deque接口?我可以使用List执行这种操作:
List<Integer> integerList = IntStream.of(1, 2, 3)
.boxed()
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
Eug*_*ene 11
您不能收集到接口,而是收集它的实现(只要是a Collection
)viaCollectors.toCollection
Deque<Integer> d = IntStream.of(1, 2)
.boxed()
.collect(Collectors.toCollection(ArrayDeque::new));
Run Code Online (Sandbox Code Playgroud)
用于Collectors.toCollection
指定所需的集合,例如:
.collect(Collectors.toCollection(ArrayDeque::new));
Run Code Online (Sandbox Code Playgroud)
或者Deque接口的任何其他实现.