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
Method | Returned stream type | Finite/Infinite | Sequential/Parallel | Ordered/Unordered |
Stream.empty() NumTypeStream.empty() (p. 893) | Stream<T> NumTypeStream | Finite | Sequential | Ordered |
Stream.of() Stream.ofNullable() NumTypeStream.of() (p. 893) | Stream<T> Stream<T> NumTypeStream | Finite | Sequential | Ordered |
Stream.generate() NumTypeStream.generate() (p. 895) | Stream<T> NumTypeStream | Infinite | Sequential | Unordered |
Stream.iterate() NumTypeStream.iterate (p. 895) | Stream<T> NumTypeStream | Infinite | Sequential | Ordered |
Stream.concat() NumTypeStream.concat() (p. 895) | Stream<T> NumTypeStream | Finite if both finite | Parallel if either parallel | Ordered if both ordered |
Collection.stream() (p. 897) | Stream<T> | Finite | Sequential | Ordered if collection ordered |
Collection.parallelStream() (p. 897) | Stream<T> | Finite | Parallel | Ordered if collection ordered |
Arrays.stream() (p. 898) | Stream<T> NumTypeStream | Finite | Sequential | Ordered |
IntStream.range() IntStream.rangeClosed() LongStream.range() LongStream.rangeClosed() (p. 898) | IntStream IntStream LongStream LongStream | Finite | Sequential | Ordered |
Random.ints() Random.longs() Random.doubles() (p. 900) | IntStream LongStream DoubleStream | Finite or infinite, depending on parameters | Sequential | Unordered |
CharSequence.chars() (p. 901) | IntStream | Finite | Sequential | Ordered |
String.lines() (p. 902) | Stream<String> | Finite | Sequential | Ordered |
BufferedReader.lines() (p. 902) | Stream<String> | Finite | Sequential | Ordered |
Files.lines() (p. 903) | Stream<String> | Finite | Sequential | Ordered |
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
M | T | W | T | F | S | S |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |