How to convert list to array in Java and vice-versa

There is no easy way to convert an array to list in Java, but you can easily convert a list into array by calling toArray() method, which List inherit from Collection interface. If you solely rely on core JDK, then only way to convert an array to list is looping over array and populating list one element at a time. But if you can use open source libraries like Google Guava or Apache Commons lang then there is many utility classes to convert list to array and vice-versa, as shown in this tutorial. If you are working on Java application, you will often need to convert between list and array. A list is nothing but a dynamic array which knows how to re-size itself when it gets full or get close to full. List uses load factor to decide when to re-size, default value of its is 0.75. When they re-size, list usually double their slots e.g. goes from 16 to 32 etc. You can find these nifty details in their implementation classes e.g. ArrayList is one of the popular list in Java which provides order and random access. BTW, if you want to truly master Java Collection framework, then you must read Java Generics and Collection book, written by Maurice Naftaline and one of the must read book to become expert on Java Collections framework.

Array to List in Java

You can use advanced for loop or classical for loop to loop over array and add each object into list using add() method, this is not a bad approach and you can easily write your own utility method say ArrayUtils.toList() to encapsulate the logic. Though you need to be aware to provide several overloaded methods for different types of array e.g. byte[], int[], short[], long[], float[], double[], char[], boolean[] and even object[]. This is cumbersome and that's why its better to use common utility library like Guava or Apache commons, which provides these kinds of handy method right from the box.

Here is how you convert an int array to List of integers in Java :
 public static List<Integer> toIntegerList(int[] intArray) {
        List<Integer> result = new ArrayList<>(intArray.length);

        for (int i : intArray) {

        return result;
Similarly, you need to write other list conversion method to convert an array of boolean, byte, short, char, long, float, double or object into corresponding List in Java.

List to Array in Java

Converting a list to an array is cakewalk, all you need to do is call the toArray() method to get all items of a list inside an array. This method is overloaded too, the one which doesn't take any parameter return an Object[] but if you want array of particular type, you can use toArray(T[]) which returns all elements of array with the type you specified. It also returns elements in the order they are stored in list. If array is not big enough to store all elements another array with sufficient size is created and returned. Just remember that, you cannot convert List to primitive array with this method, only way to do this is iterating over List and converting Integer to int using auto-boxing and storing them into array.

Here is one example of converting a List of String to an array of String in Java :
List<String> movies = Arrays.asList("Captain America", "Avatar", "Harry Potter");
String[] arrayOfMovies = new String[movies.size()];

System.out.println("list of String : " + movies);
System.out.println("array of String : " + Arrays.toString(arrayOfMovies));

Output :
list of String : [Captain America, Avatar, Harry Potter]
array of String : [Captain America, Avatar, Harry Potter]

You can see that array also contains the String in exactly same order they were in List.

How to convert array to list in Java and vice-versa

Java Program to convert list to array and vice-versa

Here is our sample program to demonstrate how to convert list to array and array to list easily in Java without using any third party library like Apache Commons Collections or Google Guava.

package dto;

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

 * Java program to convert a list to array and vice-versa.
 * @author WINDOWS 8
public class ListToArrayDemo {

    public static void main(String args[]) {

        // let's create a list first
        List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
        System.out.println("list : " + numbers);

        // let's first see how easy it is to convert a list to array
        // just call Collection.toArray() method

        // You must pass an Integer[], int[] will not work
        int[] ints = new int[numbers.size()];
        // numbers.toArray(ints); // compile time error expecting Integer[], got
        // int[]

        Integer[] integers = new Integer[numbers.size()];

        System.out.println("array converted from list : "
                + Arrays.toString(integers));

        // now let's convert an array to a list in Java
        String[] languages = { "Java", "Perl", "Lisp", "JavaScript", "Python" };

        System.out.println("array : " + Arrays.toString(languages));

        List<String> fromArray = new ArrayList<>(languages.length);

        for (String str : languages) {

        System.out.println("array to list : " + fromArray);
        // You can also create utility methods to convert array to list
        // but you need to create total of 9 method, much like various
        // println() method, one for each primitive type and one for
        // all kind of object[]. I have created two of them to
        // show you how to create them, let's see how to use them
        // now.
        List<String> names = toList(new String[]{"John", "Mohan", "Mary"});
        System.out.println("list from array in Java : " + names);
        List<Integer> primes = toIntegerList(new int[]{2, 3, 5, 7});
        System.out.println("list of Integer from an array of int : " + primes);

     * Static utility method to convert int[] to List<Integer>
    public static List<Integer> toIntegerList(int[] intArray) {
        List<Integer> result = new ArrayList<>(intArray.length);

        for (int i : intArray) {

        return result;

     * Static utility method to convert T[] to List<T> You can use this method
     * to convert any object[] to List<object.
    public static <T> List<T> toList(T[] tArray) {
        List<T> result = new ArrayList<>(tArray.length);

        for (T object : tArray) {

        return result;


Output :
list : [1, 2, 3, 4, 5, 6, 7]
array converted from list : [1, 2, 3, 4, 5, 6, 7]
array : [Java, Perl, Lisp, JavaScript, Python]
array to list : [Java, Perl, Lisp, JavaScript, Python]
list from array in Java : [John, Mohan, Mary]
list of Integer from an array of int : [2, 3, 5, 7]

That's all about how to convert a list to array and vice-versa in Java. Yes, there is no direct utility method e.g. toList(array) in JDK API to convert an array to list but its not difficult to write one, only problem is that you need to write 9 overloaded methods to convert list of 8 primitive type and one object array. Good thing is, converting list to array is relatively easy with the help of Collection.toArray() method. Just remember to provide correct type of array as autoboxing doesn't work with array. So if you want to convert a List of Integer into array, make sure you provide an array of Integer e.g. new Integer[], array of primitive int will not work e.g. new int[] will give compile time error.

If you like this tutorial and wants to learn more bout List interface from Java Collection framework, you can also check out following tutorials :
  • How to shuffle elements of list in Java? [example]
  • How to sort list in Java? [solution]
  • How to iterate over list in Java? [solution]
  • What is difference between List and Set in Java? [answer]
  • How to convert Map to List in Java? [answer]
  • How to create and initialize List in one line? [answer]
  • How to convert List to Set in Java? [example]


  1. Hi Javin. I would like to point out that unlike HashMap, ArrayList doesn't has load factor. When new item(s) are added to an ArrayList, the capacity is checked. If the internal array is full, it will grow by 50% or the size that can hold all the new items.

    1. @Clarence, Yes you are correct. ArrayList grow automatically using ensureCapacity() method. They don't have load factor. You are also correct that they increased by 50% of the size that can hold all the new elements, finally elements are copied from old array to new array using Arrays.copyOf() method. Thanks for you input, much appreciated.