17.3.1 Creating an IntStream and Displaying Its Values with the forEach Terminal Operation
IntStream static
method of (line 14) receives an int
array as an argument and returns an IntStream
for processing the array’s values. Once you create a stream, you can chain together multiple method calls to create a stream pipeline. The statement in lines 14–15 creates an IntStream
for the values
array, then uses IntStream
method forEach (a terminal operation) to perform a task on each stream element. Method forEach
receives as its argument an object that implements the IntConsumer functional interface (package java.util.function)—this is an int
-specific version of the generic Consumer
functional interface. This interface’s accept method receives one ...
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.