If you are using java-8 there's also another way to do this.

int[] arr = list.stream().mapToInt(i -> i).toArray();

What it does is:

  • getting a Stream<Integer> from the list
  • obtaining an IntStream by mapping each element to itself (identity function), unboxing the int value hold by each Integer object (done automatically since Java 5)
  • getting the array of int by calling toArray

You could also explicitly call intValue via a method reference, i.e:

int[] arr = list.stream().mapToInt(Integer::intValue).toArray();

It's also worth mentioning that you could get a NullPointerException if you have any null reference in the list. This could be easily avoided by adding a filtering condition to the stream pipeline like this:

                       //.filter(Objects::nonNull) also works
int[] arr = list.stream().filter(i -> i != null).mapToInt(i -> i).toArray();

Example:

List<Integer> list = Arrays.asList(1, 2, 3, 4);
int[] arr = list.stream().mapToInt(i -> i).toArray(); //[1, 2, 3, 4]

list.set(1, null); //[1, null, 3, 4]
arr = list.stream().filter(i -> i != null).mapToInt(i -> i).toArray(); //[1, 3, 4]
Answer from Alexis C. on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ convert-an-arraylist-containing-integers-to-primitive-int-array-in-java
How to Convert an ArrayList Containing Integers to Primitive Int Array? - GeeksforGeeks
July 23, 2025 - Two methods are mostly used to implement the ArrayList integers convert into a primitive integer array. add(): It is a pre-defined method of the ArrayList that can be used to add the elements into the ArrayList. get(): it is also an in-built ...
Top answer
1 of 16
427

If you are using java-8 there's also another way to do this.

int[] arr = list.stream().mapToInt(i -> i).toArray();

What it does is:

  • getting a Stream<Integer> from the list
  • obtaining an IntStream by mapping each element to itself (identity function), unboxing the int value hold by each Integer object (done automatically since Java 5)
  • getting the array of int by calling toArray

You could also explicitly call intValue via a method reference, i.e:

int[] arr = list.stream().mapToInt(Integer::intValue).toArray();

It's also worth mentioning that you could get a NullPointerException if you have any null reference in the list. This could be easily avoided by adding a filtering condition to the stream pipeline like this:

                       //.filter(Objects::nonNull) also works
int[] arr = list.stream().filter(i -> i != null).mapToInt(i -> i).toArray();

Example:

List<Integer> list = Arrays.asList(1, 2, 3, 4);
int[] arr = list.stream().mapToInt(i -> i).toArray(); //[1, 2, 3, 4]

list.set(1, null); //[1, null, 3, 4]
arr = list.stream().filter(i -> i != null).mapToInt(i -> i).toArray(); //[1, 3, 4]
2 of 16
266

You can convert, but I don't think there's anything built in to do it automatically:

public static int[] convertIntegers(List<Integer> integers)
{
    int[] ret = new int[integers.size()];
    for (int i=0; i < ret.length; i++)
    {
        ret[i] = integers.get(i).intValue();
    }
    return ret;
}

(Note that this will throw a NullPointerException if either integers or any element within it is null.)

EDIT: As per comments, you may want to use the list iterator to avoid nasty costs with lists such as LinkedList:

public static int[] convertIntegers(List<Integer> integers)
{
    int[] ret = new int[integers.size()];
    Iterator<Integer> iterator = integers.iterator();
    for (int i = 0; i < ret.length; i++)
    {
        ret[i] = iterator.next().intValue();
    }
    return ret;
}
๐ŸŒ
BeginnersBook -
beginnersbook.com โ€บ home โ€บ java โ€บ convert integer list to int array in java
Convert Integer List to int Array in Java
September 23, 2022 - Here, we are using toArray() method of ArrayList class to convert the given Integer ArrayList to int array. import java.util.*; public class JavaExample { public static void main(String[] args) { //A List of integers List<Integer> list= new ArrayList<>(); list.add(2); list.add(4); list.add(6); ...
๐ŸŒ
CodeAhoy
codeahoy.com โ€บ java โ€บ How-To-Convery-ArrayList-To-Array
ArrayList to Array Conversion in Java | CodeAhoy
March 1, 2020 - It will return an array containing all of the elements in this list in the proper order (from first to last element.) Hereโ€™s a short example to convert an ArrayList of integers, numbersList, to int array.
๐ŸŒ
W3Docs
w3docs.com โ€บ java
How to convert an ArrayList containing Integers to primitive int array?
List<Integer> list = new ArrayList<>(); list.add(1); list.add(2); list.add(3); int[] array = list.stream().mapToInt(i -> i).toArray(); This code will create an ArrayList containing three Integer objects, and then convert it to an int array using ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ arraylist-array-conversion-java-toarray-methods
ArrayList to Array Conversion in Java : toArray() Methods - GeeksforGeeks
July 23, 2025 - Note: toArray() method returns an array of type Object(Object[]). We need to typecast it to Integer before using as Integer objects. If we do not typecast, we get compilation error.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ java-convert-integer-list-to-int-array-117397
Java Integer List to Int Array Conversion | Programming Tutorials | LabEx
Create IntegerListToIntArray.java with the following content: import java.util.ArrayList; import java.util.List; import org.apache.commons.lang3.ArrayUtils; public class IntegerListToIntArray { public static void main(String[] args) { System.out.println("Converting Integer List to int Array Demo"); System.out.println("---------------------------------------"); // We'll add our code here in the following steps } } Compile the code using Maven: cd /home/labex/project mvn compile ยท
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 416619 โ€บ java โ€บ Convert-Integer-List-int-array
Convert Integer List to int array (Beginning Java forum at Coderanch)
Looping through the list and copying the elements into an array is the only way to do this. ... if you want to change a List<Integer> into an Integer[] you can try the Collection.toArray(T[]) method. This uses generics so is java1.5 and later only. Have a look at the javadoc for this to understand ...
Find elsewhere
๐ŸŒ
Dot Net Perls
dotnetperls.com โ€บ arraylist-integer-java
Java - ArrayList int, Integer Examples - Dot Net Perls
But in Java 8 it cannot store values. It can hold classes (like Integer) but not values (like int). To place ints in ArrayList, we must convert them to Integers. This can be done in the add() method on ArrayList. Each int must added individually. Here we have an int array, and we specify that ...
๐ŸŒ
Quora
quora.com โ€บ How-do-I-convert-arraylist-arraylist-Integer-to-int
How do I convert arraylist<arraylist<Integer>> to int[]?
Data Science, Cloud Computing, Microservices, Java Expert ยท Author has 471 answers and 3.3M answer views ยท 9y ยท We can use ArrayUtils class in Apache Commons Lang library. ... If we use List.toArray(), it will convert List to Integer[]. ... ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-convert-integer-array-list-to-integer-array-in-java
How to convert Integer array list to integer array in Java?
ArrayList < Integer > arrList = new ArrayList < Integer > (); arrList.add(100); arrList.add(200); arrList.add(300); arrList.add(400); arrList.add(500); Now, assign each value of the integer array list to integer array. We used size() to get the size of the integer array list and placed the ...
๐ŸŒ
Java67
java67.com โ€บ 2019 โ€บ 03 โ€บ how-to-convert-int-array-to-arraylist-in-java-8-example.html
How to convert int array to ArrayList of Integer in Java 8? [Example/Tutorial] | Java67
List<Integer> list = IntStream.of(primes) .boxed() .collect(Collectors.toList()); ArrayList<Integer> arraylist = new ArrayList<>(list); What is this code doing? Well, if you are not very familiar with Java 8, Stream, and method reference then ...
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 1962021 โ€บ how-do-you-convert-a-string-array-list-to-an-integer-array-list-in-java
How do you convert a String array list to an integer array list in Java? | Sololearn: Learn to code for FREE!
import java.util.Scanner; import java.util.ArrayList; import java.util.Arrays; /** This program demonstrates how to take input for an ArrayList and sums the contents if the numbers in an even index are odd as well as those numbers in an odd index if they are even. */ public class Problem2 { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); ArrayList<String> nums = new ArrayList<>(); ArrayList<Integer> nums2 = new ArrayList<>(); int sum = 0; System.out.println("Enter numbers to add to the list or -1 to quit: "); nums.add(keyboard.nextLine()); System.out.println(nums + " -> " + sum); } } java ยท
๐ŸŒ
Reddit
reddit.com โ€บ r/learnprogramming โ€บ understanding convering arraylist to an int [][];
Understanding convering ArrayList to an int [][]; : r/learnprogramming
July 20, 2022 -

I have noticed the syntax to convert an ArrayList<int[]> to a 2-d array (int[][]) is

arrName.toArray(new int[0][0]);

I am most curious about the parameters that we are sending into the toArray() method, and am curious how 'new int[0][0]' indicates this .

๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 410766 โ€บ java โ€บ Convert-ArrayList-Integers-int
Convert ArrayList of Integers to int[] (Beginning Java forum at Coderanch)
There isn't. int[] and Integer[] are not compatible, and all you can get from Collection / List etc is Object[] or Integer[]. For a second I thought that you could try using the toArray method that takes an array as parameter, but I realized that although the assignment inside the method would ...
๐ŸŒ
Quora
quora.com โ€บ How-do-I-convert-an-array-list-to-Integer-in-Java
How to convert an array list to โ€˜Integerโ€™ in Java - Quora
Answer (1 of 5): Use the Integer.parseInt () method. ArrayList strArrayList = new ArrayList ();. // Declare a new list of string strArrayList.add(โ€œ1โ€); //add string 1 inside strArrayList.add(โ€œ2โ€); //add string 2 inside int[] ArrayY = ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjava โ€บ convert list into an array in java
r/learnjava on Reddit: Convert List into an array in Java
July 17, 2020 -

Suppose we have a List<Employee> object and we want to convert it into Employee[ ].

List<Employee> list=new ArrayList<>();

We can convert list to object type array in following ways:

Employee[] empArray = list.toArray(new Employee[0]);

or

Employee[] empArray = new Employee[list.size()];

list.toArray(empArray);

But to convert arrays to primitive types. you have to convert it into following way:-

List<Integer> list = ...;

int[] array = new int[list.size()];

for(int i = 0; i < list.size(); i++) array[i] = list.get(i);

Is there any other way to convert List to its specific type of array?

๐ŸŒ
Studytonight
studytonight.com โ€บ forum โ€บ how-to-convert-int-into-list-integer-in-java
How to convert int[] into List in Java? - Studytonight
There is no shortcut for converting from int[] to List<Integer> as Arrays.asList does not deal with boxing and will just create a List<int[]> which is not what you want. You have to make a utility method. int[] ints = {1, 2, 3}; List<Integer> ...