Java Java Data Structures Exploring the Java Collection Framework Sets

Dinu Comendant
Dinu Comendant
2,788 Points

add vs addAll

I don't quite understand what's the difference between these two, since when we do a for loop, we should get the same results, regardless if we use add or addAll.

1 Answer

Steven Parker
Steven Parker
177,845 Points

The difference is that you use a loop and "add" together to add one item at a time.

But when you use "addAll" you add an entire collection at once and you don't need a loop.