How it works...

Throughout the preceding examples, we have demonstrated several stream operations already—methods of the Stream interface. We used forEach() most often and limit() a few times. The first one is a terminal operation and the second one is an intermediate one. Let's look at other methods of the Stream interface now.

Here are the intermediate operationsmethods that return Stream and can be connected in a fluent style:

//1Stream<T> peek(Consumer<T> action)//2Stream<T> distinct()       //Returns stream of distinct elementsStream<T> skip(long n)     //Discards the first n elements Stream<T> limit(long n)    //Allows the first n elements to be processed Stream<T> filter(Predicate<T> predicate)Stream<T> dropWhile(Predicate<T> predicate) Stream<T> ...

Get Java 11 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.