开发者

Adding to Arraylists

i know how to add many things into arraylist at once, like:

String [] things = {"eggs ", "pie ", "lasers ", "hat "}; List list1 = new ArrayList();

for (String s: things) 开发者_高级运维list1.add(s);

but is there a way to add things into arraylist iteratively one by one?


You ARE adding things iteratively, but if what you meant was the exact opposite

then if the elements are in any kind of Collection, you can use adAll(Collection c) or if it's an array you can use Arrays.toList(...) to convert the array to a list that you can pass to adAll

http://download.oracle.com/javase/6/docs/api/java/util/ArrayList.html


Are you looking for this:

List<String> thingsList = Arrays.asList(things); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜