Skip to content
Oracle Certified Professional Java SE 17 Developer

Summary of Stream Building Methods – Streams

Summary of Stream Building Methods

Selected methods for building streams from various data sources are listed in Table 16.1. The first column lists the method names and the reference type that provides them. For brevity, the parameters of the methods are omitted. Note that some methods are overloaded. The prefix NumType stands for Int, Long, or Double. A reference is also provided where details about the method can be found. The remaining four columns indicate various aspects of a stream: the type of stream returned by a method, whether the stream is finite or infinite, whether it is sequential or parallel, and whether it is ordered or unordered (p. 891).

Table 16.1 Summary of Stream Building Methods

MethodReturned stream typeFinite/InfiniteSequential/ParallelOrdered/Unordered
Stream.empty() NumTypeStream.empty() (p. 893)Stream<T> NumTypeStreamFiniteSequentialOrdered
Stream.of() Stream.ofNullable() NumTypeStream.of() (p. 893)Stream<T> Stream<T> NumTypeStreamFiniteSequentialOrdered
Stream.generate() NumTypeStream.generate() (p. 895)Stream<T> NumTypeStreamInfiniteSequentialUnordered
Stream.iterate() NumTypeStream.iterate (p. 895)Stream<T> NumTypeStreamInfiniteSequentialOrdered
Stream.concat() NumTypeStream.concat() (p. 895)Stream<T> NumTypeStreamFinite if both finiteParallel if either parallelOrdered if both ordered
Collection.stream() (p. 897)Stream<T>FiniteSequentialOrdered if collection ordered
Collection.parallelStream() (p. 897)Stream<T>FiniteParallelOrdered if collection ordered
Arrays.stream() (p. 898)Stream<T> NumTypeStreamFiniteSequentialOrdered
IntStream.range() IntStream.rangeClosed() LongStream.range() LongStream.rangeClosed() (p. 898)IntStream IntStream LongStream LongStreamFiniteSequentialOrdered
Random.ints() Random.longs() Random.doubles() (p. 900)IntStream LongStream DoubleStreamFinite or infinite, depending on parametersSequentialUnordered
CharSequence.chars() (p. 901)IntStreamFiniteSequentialOrdered
String.lines() (p. 902)Stream<String>FiniteSequentialOrdered
BufferedReader.lines() (p. 902)Stream<String>FiniteSequentialOrdered
Files.lines() (p. 903)Stream<String>FiniteSequentialOrdered

16.5 Intermediate Stream Operations

A stream pipeline is composed of stream operations. The stream operations process the elements of the stream to produce some result. After the creation of the initial stream, the elements of the stream are processed by zero or more intermediate operations before the mandatory terminal operation reduces the elements to some final result. The initial stream can undergo several stream transformations (technically called mappings) by the intermediate operations as the elements are processed through the pipeline.

Intermediate operations map a stream to a new stream, and the terminal operation reduces the final stream to some result. Because of the nature of the task they perform, the operations in a stream pipeline are also called map-reduce transformations.

Archives

  • July 2024
  • June 2024
  • May 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • October 2023
  • September 2023
  • May 2023
  • March 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • April 2022
  • March 2022
  • November 2021
  • October 2021
  • September 2021
  • July 2021
  • June 2021
  • March 2021
  • February 2021

Calendar

December 2022
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Nov   Jan »

Categories

  • Aspects of Streams, Revisited
  • Converting between Stream Types
  • Execution Mode of a Stream
  • Mapping between Numeric Streams
  • Oracle Exams
  • Selecting Distinct Elements

Copyright Oracle Certified Professional Java SE 17 Developer 2025 | Theme by noranebula | Proudly powered by noranebula