How to convert an array into a collection object?

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

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

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

 * Created by
 * Date: 10/6/11
public class ArrayToCollection {
    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()) {



Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.