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 […]
Converting between Stream Types – Streams
Converting between Stream Types Table 16.2 provides a summary of interoperability between stream types—that is, transforming between different stream types. Where necessary, the methods are shown with the name of the built-in functional interface required as a parameter. Selecting a naming convention for method names makes it easy to select the right method for transforming […]
Execution Mode of a Stream – Streams
Execution Mode of a Stream The two methods parallel() and sequential() are intermediate operations that can be used to set the execution mode of a stream—that is, whether it will execute sequentially or in parallel. Only the Collection.parallelStream() method creates a parallel stream from a collection, so the default mode of execution for most streams […]
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(), […]
Streams from Collections – Streams
Streams from Collections The default methods stream() and parallelStream() of the Collection interface create streams with collections as the data source. Collections are the only data source that provide the parallelStream() method to create a parallel stream directly. Otherwise, the parallel() intermediate operation must be used in the stream pipeline. The following default methods for […]
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 […]
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. […]
Streams from a BufferedReader – Streams
Streams from a BufferedReader A BufferedReader allows contents of a text file to be read as lines. A line is a sequence of characters terminated by a line terminator sequence. Details of using a Buffered-Reader are covered in §20.3, p. 1251. A simple example of creating streams on text files using a BufferedReader is presented […]
Numeric Streams Using the Random Class – Streams
Numeric Streams Using the Random Class The following methods for building numeric unordered streams are defined in the java.util.Random class: NumType is Int, Long, or Double, and the corresponding numtype is int, long, or double. The corresponding overloaded numtypes() methods are ints(), longs(), and doubles(). Click here to view code image NumTypeStreamnumtypes()NumTypeStreamnumtypes(numtype randomNumberOrigin, numtype randomNumberBound)NumTypeStreamnumtypes(long streamSize)NumTypeStreamnumtypes(long streamSize,numtype randomNumberOrigin, numtype randomNumberBound) The […]
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 |