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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.