转自:http://www.oschina.net/code/snippet_8676_2652
[代码] 数组->List (StringArrayTest.java)
01 | import java.util.Arrays; |
02 | import java.util.List; |
03 | import java.util.ArrayList; |
05 | public class StringArrayTest |
07 | public static void main(String[] args) |
09 | String[] words = { "ace" , "boom" , "crew" , "dog" , "eon" }; |
11 | List<String> wordList = Arrays.asList(words); |
13 | for (String e : wordList) |
15 | System.out.println(e); |
[代码] 比较傻的做法
1 | String[] words = { ... }; |
2 | List<String> list = new ArrayList<String>(words.length); |
3 | for (String s : words) { |
[代码] 这方法也还可以
1 | import java.util.Collections; |
3 | List myList = new ArrayList(); |
4 | String[] myStringArray = new String[] { "Java" , "is" , "Cool" }; |
6 | Collections.addAll(myList, myStringArray); |