17.3 IntStream Operations

[This section demonstrates how lambdas and streams can be used to simplify programming tasks that you learned in Chapter 7, Arrays and ArrayLists.]

Figure 17.5 demonstrates operations on an IntStream (package java.util.stream)—a specialized stream for manipulating int values. The techniques shown in this example also apply to LongStream s and DoubleStream s for long and double values, respectively.

 1   // Fig. 17.5: IntStreamOperations.java 2   // Demonstrating IntStream operations. 3   import java.util.Arrays; 4   import java.util.stream.IntStream; 5  6   public class IntStreamOperations 7   { 8      public static void main(String[] args) 9      {10         int[] values = {3, 10, 6

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.