VAKAKS

Go Back
July 24, 2024 1 min read

The Java 8 Stream API Tutorial

In this comprehensive tutorial, we’ll go through the practical uses of Java 8 Streams from creation to parallel execution.

Joe Watson SBF

Joe Watson SBF

Software Engineer

The Java 8 Stream API Tutorial
public interface Stream<T>
extends BaseStream<T,Stream<T>>
A sequence of elements supporting sequential and parallel aggregate operations. The following example illustrates an aggregate operation using Stream and IntStream:

     int sum = widgets.stream()
                      .filter(w -> w.getColor() == RED)
                      .mapToInt(w -> w.getWeight())
                      .sum();
 

When builder is used, the desired type should be additionally specified in the right part of the statement, otherwise the build() method will create an instance of the Stream<Object>:

Stream<String> streamBuilder =
  Stream.<String>builder().add("a").add("b").add("c").build();

A blog about programming, web development, and tech.

2024 VAKAKS. All rights reserved.