How to convert Array to List in java?

Below code example show how to convert an array to List in java. To convert array based data into list, we can use java.util.Arrays class. This class provide a static method asList(Object[] a) that converts array into list.

/****************************************************************************************
* Created on 10-2011Copyright(c) https://kodehelp.com All Rights Reserved.
****************************************************************************************/
package com.kodehelp.javautil;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/**
 * Created by https://kodehelp.com Date: 10/6/11
 */
public class ArrayToList {
    public static void main(String args[]) {
        String[] array = { "TOM", "JACK", "JILL", "JANE" };
        List list = Arrays.asList(array);

        Iterator iterator;
        iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println((String) iterator.next());
        }
    }
}

OUTPUT:


TOM
JACK
JILL
JANE