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 […]
The Optional Class – Streams
16.6 The Optional Class When a method returns a null value, it is not always clear whether the null value represents a valid value or the absence of a value. Methods that can return null values invariably force their callers to check the returned value explicitly in order to avoid a NullPointerException before using the […]
Lazy Execution – Streams
Lazy Execution A stream pipeline does not execute until a terminal operation is invoked. In other words, its intermediate operations do not start processing until their results are needed by the terminal operation. Intermediate operations are thus lazy, in contrast to the terminal operation, which is eager and executes when it is invoked. An intermediate […]
Concatenating Streams – Streams
Concatenating Streams The concat() method creates a resulting stream where the elements from the first argument stream are followed by the elements from the second argument stream. The code below illustrates this operation for two unordered sequential streams. Two sets are created at (1) and (2) based on lists of strings that are passed to […]
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 Factory Methods in the Files Class – Streams
Streams from Factory Methods in the Files Class A detailed discussion of the NIO2 File API that provides the classes for creating the various streams for reading files, finding files, and walking directories in the file system can be found in Chapter 21, p. 1285. Analogous to the lines() method in the BufferedReader class, a […]
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. […]
Examining Elements in a Stream – Streams
Examining Elements in a Stream The peek() operation allows stream elements to be examined at the point where the operation is used in the stream pipeline. It does not affect the stream in any way, as it only facilitates a side effect via a non-interfering consumer specified as an argument to the operation. It is […]
Finite or Infinite Stream – Streams
Finite or Infinite Stream The size of a stream can be finite or infinite depending on how the stream is created. The generate() and iterate() methods of the core stream interfaces create streams with an infinite number of elements (p. 894). Such a stream is said to be unbounded. The overloaded ints(), longs(), and doubles() […]
Aspects of Streams, Revisited – Streams
Aspects of Streams, Revisited We now take a closer look at the following aspects pertaining to streams: Table 16.3, p. 938, summarizes certain aspects of each intermediate operation. Table 16.4, p. 939, summarizes the intermediate operations provided by the Stream API. Stream Mapping Each intermediate operation returns a new stream—that is, it maps the elements […]
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 |