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));
Answer from rgettman on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › stream › IntStream.html
IntStream (Java Platform SE 8 )
March 16, 2026 - Returns a sequential ordered stream whose elements are the specified values. ... Returns an infinite sequential ordered IntStream produced by iterative application of a function f to an initial element seed, producing a Stream consisting of seed, f(seed), f(f(seed)), etc.
🌐
O'Reilly
oreilly.com › library › view › javatm-how-to › 9780133813036 › ch17lev2sec30.html
Converting an IntStream to a Stream<Integer> - Java™ How To Program (Early Objects), Tenth Edition [Book]
February 24, 2014 - Converting an IntStream to a Stream<Integer> We summarize the roll frequencies in this example by collecting them into a Map<Integer, Long> in which each Integer key is... - Selection from Java™ How To Program (Early Objects), Tenth Edition [Book]
Authors   Paul DeitelHarvey Deitel
Published   2014
Pages   1248
🌐
Medium
medium.com › @barbieri.santiago › intstream-vs-stream-integer-d78f957d5d6d
IntStream vs Stream<Integer>. Comparing IntStream against… | by Santiago | Medium
November 12, 2023 - IntStream vs Stream Comparing IntStream against Stream IntStream IntStream is a stream of primitive int values. It's part of Java's Stream API designed for primitive types. Avoid …
🌐
Medium
neesri.medium.com › primitive-type-in-stream-java-8-fb587f5c1e5b
Mastering IntStream in Java 8. In Java 8 and later versions, the… | by A cup of JAVA coffee with NeeSri | Medium
July 20, 2025 - Mastering IntStream in Java 8 In Java 8 and later versions, the Stream API is designed to work with objects, not primitive types directly. However, the Stream API provides special primitive-type …
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › util › stream › IntStream.html
IntStream (Java SE 11 & JDK 11 )
January 20, 2026 - An implementation may choose to not execute the stream pipeline (either sequentially or in parallel) if it is capable of computing the count directly from the stream source. In such cases no source elements will be traversed and no intermediate operations will be evaluated. Behavioral parameters with side-effects, which are strongly discouraged except for harmless cases such as debugging, may be affected. For example, consider the following stream: IntStream s = IntStream.of(1, 2, 3, 4); long count = s.peek(System.out::println).count(); The number of elements covered by the stream source is known and the intermediate operation, peek, does not inject into or remove elements from the stream (as may be the case for flatMap or filter operations).
🌐
HowToDoInJava
howtodoinjava.com › home › java 8 › guide to intstream in java
Guide to IntStream in Java - HowToDoInJava
March 4, 2022 - Rather an IntSupplier is provided which is a functional interface is used to generate an infinite sequential unordered stream of int values. Following example create a stream of 10 random numbers and then print them in the console. IntStream stream = IntStream .generate(() -> { return ...
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › 9 › docs › api › java › util › stream › IntStream.html
IntStream (Java SE 9 & JDK 9 )
An implementation may choose to not execute the stream pipeline (either sequentially or in parallel) if it is capable of computing the count directly from the stream source. In such cases no source elements will be traversed and no intermediate operations will be evaluated. Behavioral parameters with side-effects, which are strongly discouraged except for harmless cases such as debugging, may be affected. For example, consider the following stream: IntStream s = IntStream.of(1, 2, 3, 4); long count = s.peek(System.out::println).count(); The number of elements covered by the stream source is known and the intermediate operation, peek, does not inject into or remove elements from the stream (as may be the case for flatMap or filter operations).
🌐
Baeldung
baeldung.com › home › java › java streams › understanding the difference between stream.of() and intstream.range()
Understanding the Difference Between Stream.of() and IntStream.range() | Baeldung
March 7, 2025 - As the two Streams contain the same integer elements, we’d think after the executions, the two result lists should also contain the same integers. So next, let’s write a test to check if it produces the result we expect: List<Integer> normalStreamPeekResult = new ArrayList<>(); List<Integer> intStreamPeekResult ...
🌐
LabEx
labex.io › tutorials › java-how-to-use-intstream-in-java-streams-467224
How to use IntStream in Java streams | LabEx
Explore powerful IntStream techniques in Java for efficient numeric stream processing, filtering, mapping, and reducing integer collections with practical examples.
🌐
Mkyong
mkyong.com › home › java8 › java 8 – how to convert intstream to int or int[]
Java 8 – How to convert IntStream to int or int[] - Mkyong.com
March 2, 2020 - Few Java 8 examples to get a primitive int from an IntStream. Java8Example1.java · package com.mkyong; import java.util.Arrays; import java.util.OptionalInt; import java.util.stream.IntStream; public class Java8Example1 { public static void main(String[] args) { int[] num = {1, 2, 3, 4, 5}; //1.
🌐
TutorialsPoint
tutorialspoint.com › how-to-use-intstream-in-lambdas-and-method-references-in-java
How to use IntStream in lambdas and method references in Java?
July 13, 2020 - import java.util.*; import java.util.stream.IntStream; public class IntStreamTest { public static void main(String[] args) { final List<Integer> list = Arrays.asList(1, 2, 3); list.stream().forEach(System.out::println); // Using method reference final IntStream intStream = IntStream.iterate(1, i -> i + 1); final int sum = intStream.limit(100).sum(); System.out.println("sum: " + sum); } }
🌐
Baeldung
baeldung.com › home › java › java streams › primitive type streams in java
Primitive Type Streams in Java | Baeldung
January 8, 2024 - Streams primarily work with collections of objects and not primitive types. Fortunately, to provide a way to work with the three most used primitive types – int, long and double – the standard library includes three primitive-specialized implementations: IntStream, LongStream, and DoubleStream.
🌐
Mkyong
mkyong.com › home › java8 › java 8 – how to convert intstream to integer[]
Java 8 - How to convert IntStream to Integer[] - Mkyong.com
March 19, 2019 - The key is boxed() the IntStream into a Stream<Integer>, then only convert to an Array.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Java 8 IntStream With Working Examples - Java Code Geeks
January 3, 2022 - IntStream of(int… values) – Returns a stream with all the components supplied. range() is used to generate the numbers in the order with incremental by one.
🌐
GeeksforGeeks
geeksforgeeks.org › java › intstream-of-in-java
IntStream of() in Java - GeeksforGeeks
May 18, 2021 - Streams are not reusable if we have performed terminal operation on stream and try to reuse them again IllegalStateExeception will be generated ... import java.util.stream.IntStream; import java.io.PrintStream; class GFG{ static final PrintStream out=System.out; public static void main(String $[]){ IntStream intStream=IntStream.of(10,20,30); out.println(intStream.min()); try{ out.println(intStream.min());//Trying to use a stream that has been closed previously }catch(IllegalStateException e){ out.println(e); } } }
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › util › stream › IntStream.html
IntStream (Java SE 21 & JDK 21)
January 20, 2026 - A mutable builder for an IntStream. ... Represents an operation that accepts an int-valued argument and an IntConsumer, and returns no result. All MethodsStatic MethodsInstance MethodsAbstract MethodsDefault Methods ... Returns whether all elements of this stream match the provided predicate. ... Returns whether any elements of this stream match the provided predicate. ... Returns a DoubleStream consisting of the elements of this stream, converted to ...
🌐
Java
download.java.net › java › early_access › panama › docs › api › java.base › java › util › stream › IntStream.html
IntStream (Java SE 19 & JDK 19 [build 1])
Use is subject to license terms. ... A sequence of primitive int-valued elements supporting sequential and parallel aggregate operations. This is the int primitive specialization of Stream. The following example illustrates an aggregate operation using Stream and IntStream, computing the sum ...