Building Streams – Streams
16.4 Building Streams A stream must have a data source. In this section we will explore how streams can be created from various data sources: collections, arrays, specified values, generator functions, strings, and I/O channels, among others. Aspects to Consider When Creating Streams When creating a stream from a data source, certain aspects to consider […]
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 […]
Filtering – Streams
Filtering Filters are stream operations that select elements based on some criteria, usually specified as a predicate. This section discusses different ways of filtering elements, selecting unique elements, skipping elements at the head of a stream, and truncating a stream. The following methods are defined in the Stream<T> interface, and analogous methods are also defined […]
Order of Intermediate Operations – Streams
Order of Intermediate Operations The order of intermediate operations in a stream pipeline can impact the performance of a stream pipeline. If intermediate operations that reduce the size of the stream can be performed earlier in the pipeline, fewer elements need to be processed by the subsequent operations. Moving intermediate operations such as filter(), distinct(), […]
Setting a Stream as Unordered – Streams
Setting a Stream as Unordered The unordered() intermediate operation does not actually reorder the elements in the stream to make them unordered. It just removes the ordered constraint on a stream if this constraint is set for the stream, indicating that stream operations can choose to ignore its encounter order. Indicating the stream to be […]
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, […]
Streams from Arrays – Streams
Streams from Arrays We have seen examples of creating streams from arrays when discussing the variable arity of() method of the stream interfaces and the overloaded Arrays.stream() methods earlier in the chapter (p. 893). The sequential stream created from an array has the same order as the positional order of the elements in the array. […]
Taking and Dropping Elements Using Predicates – Streams
Taking and Dropping Elements Using Predicates Both the takeWhile() and the dropWhile() methods find the longest prefix of elements to take or drop from the input stream, respectively. The code below at (1) and (2) illustrates the case for ordered streams. The take-While() method takes odd numbers from the input stream until a number is […]
Mapping: Transforming Streams – Streams
Mapping: Transforming Streams The map() operation has already been used in several examples (Example 16.3, p. 906, Example 16.4, p. 909, and Example 16.6, p. 920). Here we take a closer look at this essential intermediate operation for data processing using a stream. It maps one type of stream (Stream<T>) into another type of stream […]
Selecting Distinct Elements – Streams
Selecting Distinct Elements The distinct() method removes all duplicates of an element from the input stream, resulting in an output stream with only unique elements. Since the distinct() method must be able to distinguish the elements from one another and keep track of them, the stream elements must override the equals() and the hashCode() methods […]
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 |