Cannot convert IntStream to some Object Stream

Stream stream2 = intStream.mapToObj( i -> new ClassName(i));

This will convert the intstream to Stream of specified object type, mapToObj accepts a function.

There is method intStream.boxed() to convert intStream directly to Stream<Integer>


The IntStream class's map method maps ints to more ints, with a IntUnaryOperator (int to int), not to objects.

Generally, all streams' map method maps the type of the stream to itself, and mapToXyz maps to a different type.

Try the mapToObj method instead, which takes an IntFunction (int to object) instead.

.mapToObj(id -> new MyObject(id));