How to convert List<Integer> to int[] in Java
Codemia Knowledge Hub ·
To turn a List<Integer> into an int[] on Java 8 and later, the shortest way is list.stream().mapToInt(Integer::intValue).toArray(). A plain for loop works on any Java version, and if you already depend on Apache Commons Lang, ArrayUtils.toPrimitive does it in one call.
Stream API (Java 8+)
The Stream API converts a List<Integer> to an int[] in one concise expression:
list.stream()creates a stream from the list..mapToInt(Integer::intValue)turns the stream ofIntegerobjects into anIntStreamof primitiveintvalues..toArray()collects the stream into a newint[].
Plain for loop
Use this before Java 8, or when you want the least overhead:
It iterates over the list and copies each value into the matching index of a new array. It is simple, just more verbose than the stream version.
Apache Commons Lang ArrayUtils
list.toArray(new Integer[0])converts theList<Integer>to anInteger[].ArrayUtils.toPrimitive()converts theInteger[]to anint[].
It is concise and readable, but it adds a dependency, so it makes most sense when the project already includes Commons Lang.
Which is fastest
Performance depends on list size and the environment. The for loop may be slightly faster than the Stream API because it has less overhead, and the Commons Lang version can be slower because it converts through an intermediate array.
| Method | Description | Performance | External Libraries Needed? |
| Stream API | Uses Java 8's Stream API to convert lists to arrays via streams. | Fast for small-medium lists | No |
| Traditional For-Loop | Manually iterates and copies elements from the list to the array. | Very Fast | No |
| Apache Commons Lang | Utilizes Apache Commons Lang’s ArrayUtils for conversion. | Medium due to additional conversions | Yes |
Pick based on your Java version, performance needs and existing dependencies: streams for concise modern code, the loop for control and speed, Commons Lang when it is already on the classpath.
Related reading
- How can I count the unique numbers in an array without rearranging the array elements?
- How can I create a generic array in Java?
- How can I create a list of elements from an iterator convert the iterator to a list?
- How can I create a two dimensional array in JavaScript?
- How can I convert my Java program to an .exe file?
- How can I create a Java 8 LocalDate from a long Epoch time in Milliseconds?
- How can I create an Array of ArrayLists?
- How can I create an external dictionary from url in clickhouse?
System design interview problems on this topic
- Design an API Rate Limiter: solution and walkthrough
- Design a Distributed Messaging System: solution and walkthrough
- Design an Online Payment Service: solution and walkthrough
- Design a Key Value Store: solution and walkthrough

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.