O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

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 used 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 operations, methods that return Stream and can be connected in a fluent style:

Stream<T> peek(Consumer<T> action)Stream<T> distinct() //Returns stream of distinct elementsStream<T> skip(long n)    //Discards the first n elements Stream<T> limit(long max) //Discards elements after max Stream<T> filter(Predicate<T> predicate)Stream<T> dropWhile(Predicate<T> predicate) Stream<T> takeWhile(Predicate<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