![]() |
VOOZH | about |
In Java, the addAll() method of the Set class is used to add all the elements of a specified collection to the current collection. The elements are added randomly without following any specific order.
Example 1: This example demonstrates how to merge two TreeSet using the addAll() method.
Initial Set: [A, B, C] Final Set: [A, B, C, D, E]
boolean addAll(Collection<? extends E> c)
Example 2: This example demonstrates how to append elements from an ArrayList to a TreeSet using the addAll() method.
Initial Set: [100, 200, 300] Final Set: [100, 200, 300, 400, 500, 600]