将字符串数组转换为ArrayList

我想将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);

}

}

}

以上是 将字符串数组转换为ArrayList 的全部内容, 来源链接: utcz.com/qa/426381.html

回到顶部