我想将 String
数组转换为 ArrayList
。例如字符串数组是这样的:
String[] words = new String[]{"ace","boom","crew","dog","eon"};
如何将这个String数组转换为ArrayList?
最佳答案
使用此代码,
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);
}
}
}
关于java - 将字符串数组转换为 ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10530353/