How do I turn a list into an array in Java?

We can use toArray() methods of List to convert them to an array.

1. Use toArray() method without parameter.

Object[] toArray()


An array containing all of the elements in this list in proper sequence.

2. Use toArray() with array of specific type of elements.

<T> T[] toArray(T[] a)


  • a − The array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.


An array containing the elements of this list.


  • ArrayStoreException − If the runtime type of the specified array is not a supertype of the runtime type of every element in this list.

  • NullPointerException − If the specified array is null.


Following is the example showing the usage of toArray() methods −

package com.tutorialspoint;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class CollectionsDemo {
   public static void main(String[] args) {
      List<Integer> list = new ArrayList<>(Arrays.asList(1,2,3,4));
      System.out.println("List: " + list);
      Object[] items = list.toArray();
      for (Object object : items) {
         System.out.print(object + " ");
      Integer[] numbers = list.toArray(new Integer[0]);
      for (Integer number : numbers) {
         System.out.print(number + " ");


This will produce the following result −

List: [1, 2, 3, 4]
1 2 3 4
1 2 3 4