You can use the collect operation that you have on IntStream instead of boxing it into a Stream<Integer>.

IntStream.range(0, productReferences.length)
         .filter(index -> productsPrice[index] != null)
         .collect(
            HashMap::new,
            (m, i) -> m.put(productReferences[i], callSomeMethod(productsPrice[i])),
            Map::putAll
         );

This won't box every index into an Integer since the consumer part of the collector takes an ObjIntConsumer; so i in the code above is an int. As Holger noted, the initial code, using Collectors.toMap would throw an exception in the case of duplicate keys, when this version would overwrite the value.

You would still need to benchmark the two solutions on your real data to see if that brings an improvement.

Answer from Tunaki 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 Stream consisting of the elements of this stream, each boxed to an Integer.
🌐
HowToDoInJava
howtodoinjava.com › home › java 8 › boxed streams in java
Boxed Streams in Java - Stream of Primitives
March 3, 2022 - In Java, a boxed stream is a stream of the wrapper class instances to simulate a stream of primitives. Java Stream API has been designed to work with objects, similar to Collections API.
🌐
GeeksforGeeks
geeksforgeeks.org › java › intstream-boxed-java
IntStream boxed() in Java - GeeksforGeeks
July 11, 2025 - Stream<Integer> stream1 = stream.boxed(); // Displaying the elements stream1.forEach(System.out::println); } } Output : ... // Java code for IntStream boxed() import java.util.*; import java.util.stream.Stream; import java.util.stream.IntStream; class GFG { // Driver code public static void main(String[] args) { // Creating an IntStream IntStream stream = IntStream.range(3, 8); // Creating a Stream of Integers // Using IntStream boxed() to return // a Stream consisting of the elements // of this stream, each boxed to an Integer.
🌐
DEV Community
dev.to › imanuel › the-java-boxed-method-571n
The Java `.boxed()` Method - DEV Community
June 19, 2022 - What the .boxed() method does is that it returns a Stream consisting of the elements of the given stream, each boxed to an object of the corresponding wrapper class.
🌐
TutorialsPoint
tutorialspoint.com › intstream-boxed-method-in-java
IntStream boxed() method in Java
July 30, 2019 - The boxed() method of the IntStream class returns a Stream consisting of the elements of this stream, each boxed to an Integer. The syntax is as follows. At first, create an IntStream Now, use the boxed() method to return a Stream consisting of the
🌐
Medium
neesri.medium.com › java-8-difference-between-boxed-and-map-14bfc13180dc
JAVA 8- Difference between boxed and map. | by A cup of JAVA coffee with NeeSri | Medium
January 15, 2024 - The boxed method is used to convert a stream of primitive values (like IntStream, DoubleStream, LongStream) into a stream of their corresponding wrapper classes (e.g., Integer, Double, Long).
🌐
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 - Returns a Stream consisting of the elements of this stream, each boxed to an Integer. This is an intermediate operation. ... Returns a builder for an IntStream.
🌐
Tabnine
tabnine.com › home page › code › java › java.util.stream.intstream
java.util.stream.IntStream.boxed java code examples | Tabnine
*/ protected ArrayList<TreeRoot> initTrees(Queue<TreeNode> treesQueue) { assert featuresPerTree > 0; ArrayList<TreeRoot> roots = new ArrayList<>(); List<Integer> allFeatureIds = IntStream.range(0, meta.size()).boxed().collect(Collectors.toList()); for (TreeNode node : treesQueue) { Collections.shuffle(allFeatureIds, random); Set<Integer> featuresSubspace = allFeatureIds.stream() .limit(featuresPerTree).collect(Collectors.toSet()); roots.add(new TreeRoot(node, featuresSubspace)); } return roots; }
Find elsewhere
🌐
Blogger
java8example.blogspot.com › 2019 › 08 › java-8-intstream-boxed.html
Java 8 IntStream boxed() Method Example Java8Example
In this tutorial, We'll learn about the new java 8 IntStream API boxed() method. IntStream boxed() returns a Stream consisting of the elements of this stream, each boxed to an Integer. That means to convert all primitive int values to wrapper Integer type objects Stream.
🌐
Java2s
java2s.com › Tutorials › Java › java.util.stream › IntStream › IntStream.boxed_.htm
Java Streams - IntStream boxed() example
j ava 2s . c o m*/ public class Main { public static void main(String[] args) { IntStream i = IntStream.of(1,2,3,4,5,6,7); Stream< Integer> o = i.boxed(); o.forEach(System.out::println); } }
🌐
Javaprogramto
javaprogramto.com › 2019 › 12 › java-8-boxed-stream-operations.html
Java 8 Program To Boxed Stream Operations JavaProgramTo.com
In this tutorial, We'll learn how to convert primitives to wrapper objects in java 8. Java programs to convert a stream of int, long, double values into Collection using boxed() method.
🌐
Netjstech
netjstech.com › 2022 › 01 › java-stream-boxed-with-examples.html
Java Stream - boxed() With Examples | Tech Tutorials
In Java stream API there are primitive specializations of Stream named IntStream, LongStream and DoubleStream and each of these interfaces has a boxed() method that returns a Stream consisting of the elements of this stream, each boxed to an Integer, Long or Double respectively.
🌐
Oracle
docs.oracle.com › en › java › javase › 26 › docs › api › java.base › java › util › stream › IntStream.html
IntStream (Java SE 26 & JDK 26)
March 16, 2026 - Returns a Stream consisting of the elements of this stream, each boxed to an Integer. ... Returns a builder for an IntStream.
🌐
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 - Returns a Stream consisting of the elements of this stream, each boxed to an Integer. ... Returns a builder for an IntStream.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › util › stream › IntStream.html
IntStream (Java SE 17 & JDK 17)
January 20, 2026 - Returns a Stream consisting of the elements of this stream, each boxed to an Integer. ... Returns a builder for an IntStream.