O'Reilly logo

Functional Programming in Java by Venkat Subramaniam

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

Leveraging the Laziness of Streams

In previous chapters we’ve seen the facilities that the new Stream interface offers, but so far we haven’t discussed one of their most salient features—they’re really lazy, in a good way. The lazy evaluation of Streams is quite powerful. First, we don’t have to do anything special to derive their benefits. In fact, we’ve used them many times already! Second, they can postpone not just one, but a sequence of evaluations so that only the most essential parts of the logic are evaluated, and only when needed. Let’s look at how lazy Streams are and how we benefit from that.

Intermediate and Terminal Operations

Streams have two types of methods: intermediate and terminal, which work together. The secret behind their ...

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