O'Reilly logo

Java 11 Cookbook by Mohamed Sanaulla, Nick Samoylov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required