Open In App

SortedSet addAll() method in Java with Examples

Last Updated : 12 Jul, 2025
Comments
Improve
Suggest changes
167 Likes
Like
Report
The addAll(Collection C) method is used to append all of the elements from the mentioned collection to the existing set. The elements are added randomly without following any specific order. Syntax:
boolean addAll(Collection C)
Parameters: The parameter C is a collection of any type that is to be added to the set. Return Value: The method returns true if it successfully appends the elements of the collection C to this Set otherwise it returns False. Note: The addAll() method in SortedSet is inherited from the Set interface in Java. Below programs illustrate the Java.util.Set.addAll() method: Program 1 : Appending a tree set.
Output:
Set: [4, Geeks, To, TreeSet, Welcome]
Set: [4, Geeks, Hello, To, TreeSet, Welcome, World]
Program 2 : Appending an ArrayList.
Output:
Initial Set: [4, Geeks, Set, To, Welcome]
Final Set: [4, A, Computer, Geeks, Portal, Set, To, Welcome]
Reference: https://docs.oracle.com/javase/7/docs/api/java/util/Set.html#addAll(java.util.Collection)

Practice Tags :

Similar Reads