Streams from a CharSequence – Streams
Streams from a CharSequence The CharSequence.chars() method creates a finite sequential ordered IntStream from a sequence of char values. The IntStream must be transformed to a Stream<Character> in order to handle the values as Characters. The IntStream.mapToObj() method can be used for this purpose, as shown at (2). A cast is necessary at (2) in […]
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 […]
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 […]
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 […]
Truncating a Stream – Streams
Truncating a Stream The limit() operation returns an output stream whose maximum size is equal to the max size specified as an argument to the method. The input stream is only truncated if its size is greater than the specified max size. In Figure 16.6, Query 4 creates a list with the first two CDs […]
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() […]
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 […]
Flattening Streams – Streams
Flattening Streams The flatMap() operation first maps each element in the input stream to a mapped stream, and then flattens the mapped streams to a single stream—that is, the elements of each mapped stream are incorporated into a single stream when the pipeline is executed. In other words, each element in the input stream may […]
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 […]
Replacing Each Element of a Stream with Multiple Elements – Streams
Replacing Each Element of a Stream with Multiple Elements The mapMulti() intermediate operation applies a one-to-many transformation to the elements of the stream and flattens the result elements into a new stream. The functionality of the mapMulti() method is very similar to that of the flatMap() method. Whereas the latter uses a Function<T, Stream<R>> mapper […]
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 |