Collections 将Java8 IntStream收集到Deque接口中

Collections 将Java8 IntStream收集到Deque接口中,collections,java-8,Collections,Java 8,如何将Java8 IntStream收集到接口中? 我可以使用如下列表执行此类操作: List<Integer> integerList = IntStream.of(1, 2, 3) .boxed() .collect(Collectors.toList()); List integerList=IntStream.of(1,2,3)

如何将Java8 IntStream收集到接口中? 我可以使用如下列表执行此类操作:

List<Integer> integerList = IntStream.of(1, 2, 3)
                                     .boxed()
                                     .collect(Collectors.toList());
List integerList=IntStream.of(1,2,3)
.boxed()
.collect(Collectors.toList());

您不能通过
收集器收集到接口,而是收集到接口的一个实现(只要它是
集合

 Deque<Integer> d = IntStream.of(1, 2)
            .boxed()
            .collect(Collectors.toCollection(ArrayDeque::new));
Deque d=IntStream.of(1,2)
.boxed()
.collect(收集器.toCollection(ArrayDeque::new));

使用
收集器。toCollection
指定所需的集合,例如:

.collect(Collectors.toCollection(ArrayDeque::new));

或接口的任何其他实现。

像螺栓一样快速^_^