关于java:如何一次向arraylist添加多个值?

How to add many values to an arraylist at once?
假设我有以下代码:

String a =" some texte";
String b =" text";
String c ="sf";
String d =" kjel";
String e ="lkjl";

ArrayList<String> list = new ArrayList<String>();
// better way to do all these adds without having to type them all?
list.add(a);
list.add(b);
list.add(c);
list.add(d);
list.add(e);

可以:

list.addAll(Arrays.asList(a, b, c, d, e));

也可以:

ArrayList<String> list = Lists.newArrayList(a, b, c, d, e);
THE END
< <上一篇
下一篇>>