Convert String Array To List - Java Collection Framework

Java examples for Collection Framework:List

Description

Convert String Array To List

Demo Code

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

public class Main {

  public static void main(String args[]) {

    String[] numbers = new String[] { "one", "two", "three","java2s.com" };

    List list = (List) Arrays.asList(numbers);

    System.out.println("String array converted to List");
    for (int i = 0; i < list.size(); i++) {
      System.out.println(list.get(i));
    }/*from   w  w  w.ja  v  a2 s .c  o  m*/

    List anotherList = new ArrayList();

    Collections.addAll(anotherList, numbers);
    System.out.println(anotherList);
  }
}

Result


Related Tutorials