Summary of Intermediate Stream Operations – Streams
Summary of Intermediate Stream Operations
Table 16.3 summarizes selected aspects of the intermediate operations.
Table 16.3 Selected Aspects of Intermediate Stream Operations
Intermediate operation | Stateful/Stateless | Can change stream size | Can change stream type | Encounter order |
distinct (p. 915) | Stateful | Yes | No | Unchanged |
dropWhile (p. 913) | Stateful | Yes | No | Unchanged |
filter (p. 910) | Stateless | Yes | No | Unchanged |
flatMap (p. 921) | Stateless | Yes | Yes | Not guaranteed |
limit (p. 917) | Stateful, short-circuited | Yes | No | Unchanged |
map (p. 921) | Stateless | No | Yes | Not guaranteed |
mapMulti (p. 927) | Stateless | Yes | Yes | Not guaranteed |
parallel (p. 933) | Stateless | No | No | Unchanged |
peek (p. 920) | Stateless | No | No | Unchanged |
sequential (p. 933) | Stateless | No | No | Unchanged |
skip (p. 915) | Stateful | Yes | No | Unchanged |
sorted (p. 929) | Stateful | No | No | Ordered |
takeWhile (p. 913) | Stateful, short-circuited | Yes | No | Unchanged |
unordered (p. 932) | Stateless | No | No | Not guaranteed |
The intermediate operations of the Stream<T> interface (including those inherited from its superinterface BaseStream<T,Stream<T>>) are summarized in Table 16.4. The type parameter declarations have been simplified, where any bounds <? super T> or <? extends T> have been replaced by <T>, without impacting the intent of a method. A reference is provided to each method in the first column. Any type parameter and return type declared by these methods are shown in column two.
The last column in Table 16.4 indicates the function type of the corresponding parameter in the previous column. It is instructive to note how the functional interface parameters provide the parameterized behavior of an operation. For example, the filter() method returns a stream whose elements satisfy a given predicate. This predicate is defined by the functional interface Predicate<T> that is implemented by a lambda expression or a method reference, and applied to each element in the stream.
The interfaces IntStream, LongStream, and DoubleStream also define analogous methods to those shown in Table 16.4, except for the flatMapToNumType() methods, where NumType is either Int, Long, or Double. A summary of additional methods defined by these numeric stream interfaces can be found in Table 16.2.
Table 16.4 Intermediate Stream Operations
Method name | Any type parameter + return type | Functional interface parameters | Function type of parameters |
distinct (p. 915) | Stream<T> | () | |
dropWhile (p. 913) | Stream<T> | (Predicate<T> predicate) | T -> boolean |
filter (p. 910) | Stream<T> | (Predicate<T> predicate) | T -> boolean |
flatMap (p. 921) | <R> Stream<R> | (Function<T,Stream<R>> mapper) | T -> Stream<R> |
flatMapToDouble (p. 921) | DoubleStream | (Function<T,DoubleStream> mapper) | T -> DoubleStream |
flatMapToInt (p. 921) | IntStream | (Function<T,IntStream> mapper) | T -> IntStream |
flatMapToLong (p. 921) | LongStream | (Function<T,LongStream> mapper) | T -> LongStream |
limit (p. 917) | Stream<T> | (long maxSize) | |
map (p. 921) | <R> Stream<R> | (Function<T,R> mapper) | T -> R |
mapMulti (p. 927) | <R> Stream<R> | (BiConsumer<T,Consumer<R>> mapper) | (T, Consumer<R>) -> void |
mapToDouble (p. 921) | DoubleStream | (ToDoubleFunction<T> mapper) | T -> double |
mapToInt (p. 921) | IntStream | (ToIntFunction<T> mapper) | T -> int |
mapToLong (p. 921) | LongStream | (ToLongFunction<T> mapper) | T -> long |
parallel (p. 933) | Stream<T> | () | |
peek (p. 920) | Stream<T> | (Consumer<T> action) | T -> void |
sequential (p. 933) | Stream<T> | () | |
skip (p. 915) | Stream<T> | (long n) | |
sorted (p. 929) | Stream<T> | () | |
sorted (p. 929) | Stream<T> | (Comparator<T> cmp) | (T,T) -> int |
takeWhile (p. 913) | Stream<T> | (Predicate<T> predicate) | T -> boolean |
unordered (p. 932) | Stream<T> | () |
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 |