Search code examples
javajava-8java-streameclipse-collections

Create an IntStream and a Stream<Integer> from an Eclipse Collections IntList/IntIterable


I have an Eclipse Collections IntList. How can I

  1. Create a Java IntStream from this list
  2. Create a Java Stream<Integer> from this list

without copying the elements?


Solution

  • With Eclipse Collections 10.0 you can now call primitiveStream directly on IntList.

    IntStream intStream = IntLists.mutable.with(1, 2, 3, 4, 5).primitiveStream();
    
    Stream<Integer> stream = intStream.boxed();