4 ms·
For those who know C#: It's the Java version of LINQ. For those who don't know Java and C#: All regular collections now offer a .stream() (and .parallelStream(
by Traubenfuchs 10y ago
For those who know C#: It's the Java version of LINQ.
For those who don't know Java and C#: All regular collections now offer a .stream() (and .parallelStream()) method that returns the collection as Java 8 Stream<T> instance. With the help of lambda expressions, objects of a stream can be converted/mapped, filtered, sorted, aggregated, reduced, flatmapped, etc. by chaining methods on the stream. You can also create finite or infinite streams without a collection (Like of numbers ranges, random values or anything else you can think of).
I often end up writing complex stream method chains just to break them up in the end, thinking that they are too difficult to understand for others.