Streams

The other major addition to Java 8, and, perhaps where lambdas shine the brightest, is the new Streams API. If you were to search for a definition of Java streams, you would get answers that range from the somewhat circular a stream of data elements to the more technical Java streams are monads, and they're probably both right. The Streams API allows the Java developer to interact with a stream of data elements via a sequence of steps. Even putting it that way isn't as clear as it could be, so let's see what it means by looking at some sample code.

Let's say you have a list of grades for a particular class. You would like to know what the average grade is for the girls in the class. Prior to Java 8, you might have written something ...

Get Java 9: Building Robust Modular Applications 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.