0

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

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

        for (String x: things)
            list1.add(x);

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

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by JamesCherrill
1

If the things are in any kind of Collection you can use addAll(Collection c),
If it''s an array you can use Arrays.toList(...) to convert the array to a List that you can pass to addAll

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

That is exactly what your code is doing!

Edited by JamesCherrill: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.