So I understand you can have object streams, i.e. Stream<T>
and specialist primitive streams, e.g. IntStream
, DoubleStream
, etc. One of the benefits of the latter is to avoid autoboxing.
Also if we take IntStream
as an example, it has specialised operations such as filter that accepts an IntPredicate
.
I wondered if I had an IntStream
vs a Stream<Integer>
at which point you're saving on boxing, e.g.
intstream.filter(x -> x >= 50).forEach(x -> System.out.println(x));
vs
stream.filter(x -> x >= 50).forEach(x -> System.out.println(x));
In the first example, there is no boxing or unboxing that I can see. In the second example where is the boxing / unboxing occurring? Because if stream is a Stream<Integer>
and the filter accepts a Predicate<Integer>
then surely there's no need to box/unbox, and the same for IntConsumer
vs Consumer<T>
?