Java Language Streams

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

A Stream represents a sequence of elements and supports different kind of operations to perform computations upon those elements. With Java 8, Collection interface has two methods to generate a Stream: stream() and parallelStream(). Stream operations are either intermediate or terminal. Intermediate operations return a Stream so multiple intermediate operations can be chained before the Stream is closed. Terminal operations are either void or return a non-stream result.

Syntax

  • collection.stream()
  • Arrays.stream(array)
  • Stream.iterate(firstValue, currentValue -> nextValue)
  • Stream.generate(() -> value)
  • Stream.of(elementOfT[, elementOfT, ...])
  • Stream.empty()
  • StreamSupport.stream( iterable.spliterator(), false )


Got any Java Language Question?