Convert String array to String list - Java Collection Framework

Java examples for Collection Framework:Array Convert

Description

Convert String array to String list

Demo Code


//package com.java2s;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] argv) throws Exception {
        String[] array = new String[] { "1", "abc", "level", null,
                "java2s.com", "asdf 123" };
        System.out.println(stringArrayToStringList(array));
    }/*from   w  ww. j  a  va  2 s .c o  m*/

    /**
     * Convert String array to String list
     * @param array
     * @return
     */
    public static List<String> stringArrayToStringList(String[] array) {
        List<String> result = new ArrayList<String>();
        for (int i = 0; i < array.length; i++) {
            result.add(array[i]);
        }
        return result;
    }
}

Related Tutorials