IntStream::boxed

IntStream::boxed turns an IntStream into a Stream<Integer>, which you can then collect into a List:

theIntStream.boxed().collect(Collectors.toList())

The boxed method converts the int primitive values of an IntStream into a stream of Integer objects. The word "boxing" names the intInteger conversion process. See Oracle Tutorial.

Java 16 and later

Java 16 brought the shorter toList method. Produces an unmodifiable list. Discussed here.

theIntStream.boxed().toList() 
Answer from Ian Roberts on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java streams › java intstream conversions
Java IntStream Conversions | Baeldung
January 8, 2024 - In this example, we make use of the method range. The most notorious part here is using the method boxed, that, as its name points out, will box all the int elements in the IntStream and will return a Stream<Integer>. Finally, we can use a collector to get a list of integers.
🌐
HowToDoInJava
howtodoinjava.com › home › java 8 › collecting stream of primitives into collection or array
Collecting Stream of Primitives into Collection or Array
March 14, 2022 - Another way is to manually to the boxing using IntStream.mapToObj(), IntStream.mapToLong() or IntStream.mapToDouble() methods. There are other similar methods in other stream classes, which you can use. //Primitive Stream -> List List<Integer> listOfIntegers = IntStream.of(1,2,3,4,5) .mapToObj(Integer::valueOf) .collect(Collectors.toList()); List<Long> listOfLongs = LongStream.of(1,2,3,4,5) .mapToObj(Long::valueOf) .collect(Collectors.toList()); List<Double> listOfDoubles = DoubleStream.of(1.0,2.0,3.0,4.0,5.0) .mapToObj(Double::valueOf) .collect(Collectors.toList());
🌐
Dirask
dirask.com › posts › Java-8-convert-Int-Stream-to-list-with-Collectors-error-fix-v10EaD
Java 8 - convert Int Stream to list with Collectors - error fix
// ERROR reproduction: // Error:(18, 17) java: method collect in interface // java.util.stream.IntStream cannot be applied to given types; // ... // IntStream.of(1, 2, 3, 4, 5) // .collect(Collectors.toList()); // FIX: List<Integer> collect = IntStream.of(1, 2, 3, 4, 5) .boxed() // <-- this line fix the problem .collect(Collectors.toList()); // [1, 2, 3, 4, 5] System.out.println(collect); Full stack trace from intellij idea: Error:(18, 17) java: method collect in interface java.util.stream.IntStream cannot be applied to given types; required: java.util.function.Supplier<R>, java.util.function.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Java 8 - Convert IntStream To List and Other - Java Code Geeks
November 27, 2021 - In java 8 API, IntStream class has boxed() method. boxed() method converts the primitive int values into a stream of integer objects. Once we get the Stream<Integer> instance then we can convert it to the List or Set or Map or any collection.
🌐
Codemia
codemia.io › knowledge-hub › path › how_do_i_convert_a_java_8_intstream_to_a_list
How do I convert a Java 8 IntStream to a List?
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
🌐
frhyme.code
frhyme.github.io › java › java_IntStream_to_List_simple_and_difficult
Java - stream - IntStream to List : frhyme.code
December 25, 2020 - import java.util.*; import java.util.stream.*; class Main { public static void main(String[] args) throws Exception { List<Integer> lst = IntStream.rangeClosed(1, 10) .filter( x -> (x % 3 == 0) | (x % 7 == 0) ) .collect(Collectors.toList()); System.out.println(lst); // [3, 6, 7, 9] } }
🌐
HowToDoInJava
howtodoinjava.com › home › java 8 › java collect stream to list (with examples)
Java Collect Stream to List (with Examples)
April 29, 2024 - Stream<Employee> employeeStream = Stream.of( new Employee(1, "A", 100), new Employee(2, "B", 200), new Employee(3, "C", 300), new Employee(4, "D", 400), new Employee(5, "E", 500), new Employee(6, "F", 600)); List<Employee> employeeList = employeeStream .filter(e -> e.getSalary() < 400) .collect(Collectors.toList()); To convert an infinite stream into a list, we must limit the stream to a finite number of elements. Given example will work in the case of a stream of primitives. IntStream infiniteNumberStream = IntStream.iterate(1, i -> i+1); List<Integer> integerlist = infiniteNumberStream.limit(10) .boxed() .collect(Collectors.toList()); In this tutorial, we learned the different ways to work with streams and collect the stream items in a List.
Find elsewhere
🌐
Tabnine
tabnine.com › home page › code › java › java.util.stream.intstream
How to use collect method in java.util.stream.IntStream
protected String randomStringFullOfInt(Random random, int digits) { return random.ints(digits, 0, 10).collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString(); } } ... @Test public void testShuffled() { List<Integer> list = IntStream.range(0, INPUT_SIZE).collect(ArrayList::new, ArrayList::add, ArrayList::addAll); Collections.shuffle(list); test(list.stream().mapToInt(Integer::intValue), MAX_ELEMENTS_COMPARATOR, IntStream.range(INPUT_SIZE - OUTPUT_SIZE, INPUT_SIZE).iterator()); test(list.stream().mapToInt(Integer::intValue), MIN_ELEMENTS_COMPARATOR, IntStream.range(0, OUTPUT_SIZE).map(x -> OUTPUT_SIZE - 1 - x).iterator()); }
🌐
Baeldung
baeldung.com › home › java › java streams › collecting stream elements into a list in java
Collecting Stream Elements into a List in Java | Baeldung
December 3, 2025 - However, there have been change requests for a method to get a List directly from a Stream instance. With the Java 16 release, we can now invoke toList(), a new method directly on the Stream, to get the List.
🌐
Kotlin
kotlinlang.org › api › latest › jvm › stdlib › kotlin.streams › java.util.stream.-int-stream › to-list.html
toList - Kotlin Programming Language
June 9, 2023 - fun IntStream.toList(): List<Int> (source) Returns a List containing all elements produced by this stream.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › stream › IntStream.html
IntStream (Java Platform SE 8 )
March 16, 2026 - May return itself, either because ... modified to be parallel. This is an intermediate operation. ... Returns an iterator for the elements of this stream. This is a terminal operation. ... Returns a spliterator for the elements of this stream. This is a terminal operation. ... Returns a builder for an IntStream...
🌐
ConcretePage
concretepage.com › java › java-10 › convert-java-stream-to-list
Convert Java Stream to List
October 17, 2020 - package com.concretepage; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; public class ExampleToList { public static void main(String[] args) { List<Integer> list1 = Stream.of(15, 20, 30) .collect(Collectors.toList()); System.out.println(list1); List<Integer> list2 = IntStream.range(15, 20).boxed() .collect(Collectors.toList()); System.out.println(list2); List<Integer> list3 = Arrays.asList(2, 4, 6).stream().map(i -> i * 2) .collect(Collectors.toList()); System.out.println(list3); List<String> list4 = Stream.of("Mahesh", "Krishn", "Shiv") .collect(Collectors.toList()); System.out.println(list4); } } Output ·
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Java 8 IntStream With Working Examples - Java Code Geeks
January 3, 2022 - Use collect() method to collect the output of IntStream into List or Set.
🌐
Tabnine
tabnine.com › home page › code › java › java.util.stream.intstream
java.util.stream.IntStream.range java code examples | Tabnine
private String columnDefinitions(List<DataTypeTest.Input<?>> inputs) { List<String> columnTypeDefinitions = inputs.stream() .map(DataTypeTest.Input::getInsertType) .collect(toList()); Stream<String> columnDefinitions = range(0, columnTypeDefinitions.size()) .mapToObj(i -> format("col_%d %s", i, columnTypeDefinitions.get(i))); return Joiner.on(",\n").join(columnDefinitions.iterator()); } } ... protected String formatInvokeError(String text, Object[] args) { String formattedArgs = IntStream.range(0, args.length) .mapToObj(i -> (args[i] != null ?
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-stream-collect-method-examples
Java Stream collect() Method Examples | DigitalOcean
August 3, 2022 - Stream filter() is an intermediate operation and returns a stream. So, we will use the collect() function to create the list from this stream.
🌐
Learn IT University
learn-it-university.com › home › effortless conversion: transforming java 8 intstream to a list in simple steps
Effortless Conversion: Transforming Java 8 IntStream to a List in Simple Steps - Learn IT University
July 21, 2024 - The following content will provide ... method for converting an IntStream into a List involves the use of the boxed() method followed by a collector....
🌐
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 - Reduction operations in IntStream are performed using methods like reduce, sum, average, min, and max. These operations aggregate the elements of the stream into a single result by applying a binary operator to each element.
🌐
HowToDoInJava
howtodoinjava.com › home › java 8 › guide to intstream in java
Guide to IntStream in Java - HowToDoInJava
March 4, 2022 - For example, we can iterate over int values and filter/collect all prime numbers up to a certain limit. IntStream stream = IntStream.range(1, 100); List<Integer> primes = stream.filter(ThisClass::isPrime) .boxed() .collect(Collectors.toList()); public static boolean isPrime(int i) { IntPredicate isDivisible = index -> i % index == 0; return i > 1 && IntStream.range(2, i).noneMatch(isDivisible); } Use IntStream.toArray() method to convert from the stream to int array.