Delving into primitive streams
Thus far, all our streams have been for Object
types. For example, a Stream<Integer>
caters for the wrapper class Integer
. Java also has classes specifically tailored for streams of primitives. For example, assuming a stream of int
primitives, rather than Stream<Integer>
, we use IntStream
. As we shall see shortly, primitive streams have some really useful methods for processing numeric data, such as sum()
and average()
.
Table 16.1 introduces the primitive stream classes.
Wrapper stream |
Primitive stream |
Primitives catered for |
|
|
|
|
|
|
|