Internal Iteration

In functional programming, you specify what you want to accomplish in a task, but not how to accomplish it. As you’ll see in this chapter, to sum a numeric data source’s elements (such as those in an array or collection), you can use new Java SE 8 library capabilities that allow you to say, “Here’s a data source, give me the sum of its elements.” You do not need to specify how to iterate through the elements or declare and use any mutable variables. This is known as internal iteration, because the library determines how to access all the elements to perform the task. With internal iteration, you can easily tell the library that you want to perform this task with parallel processing to take advantage of your computer’s multi-core ...

Get Java™ How To Program (Early Objects), Tenth Edition 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.