java 数组转List

import java.util.Arrays;

import java.util.List;

import java.util.ArrayList;



public class StringArrayTest

{

   public static void main(String[] args)

   {

      String[] words = {"ace", "boom", "crew", "dog", "eon"};

 

      List<String> wordList = Arrays.asList(words);

 

      for (String e : wordList)

      {

         System.out.println(e);

      }

   }

}

String[] words = { ... };
List<String> list = new ArrayList<String>(words.length);
for (String s : words) {
list.add(s);
}
import java.util.Collections;

List myList = new ArrayList();
String[] myStringArray = new String[] {"Java", "is", "Cool"};

Collections.addAll(myList, myStringArray);


http://www.oschina.net/code/snippet_8676_2652
主要要注意,第一种方法转换的不能add和remove

Arrays.asList

你可能感兴趣的:(java)