Java TreeSet addAll() Method

The addAll() method of TreeSet class is used to add elements of one set to another set.

Syntax:

Parameter:

c- elements to be add to the set.

Return:

It returns true if set is changed else it returns false

Example 1

Output:

TreeSet: [7, 10, 13, 20] [1, 3, 6, 9]
true
TreeSet after adding: [1, 3, 6, 7, 9, 10, 13, 20]

Example 2

Output:

TreeSet: [ 1, 2, 5, 8, 10 ]
false
TreeSet: [ 1, 2, 5, 8, 10 ]

Example 3

Output:

TreeSet: [ A, B, a, b ] [ 1, 3, 6, 9 ]
true
TreeSet: [ 1, 3, 6, 9, A, B, a, b ]