2010년 10월 25일 월요일

String array to arraylist


String array to arraylist

vani mn
Greenhorn

Joined: Jan 21, 2006
Posts: 1
How to convert a string array to arraylist??
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1285
If the concrete implementation doesn't matter, you can use Arrays.asList() to convert your array to a List.
  1. import java.util.Arrays;
  2. import java.util.List;
  3. import java.util.ArrayList;
  4. public class StringArrayTest
  5. {
  6. public static void main(String[] args)
  7. {
  8. String[] words = {"ace", "boom", "crew", "dog", "eon"};
  9. List wordList = Arrays.asList(words);
  10. for (String e : wordList)
  11. {
  12. System.out.println(e);
  13. }
  14. }
  15. }