TreeSet.addAll(Collection <? extends E > c) has the following syntax.
public boolean addAll(Collection <? extends E> c)
In the following code shows how to use TreeSet.addAll(Collection <? extends E > c) method.
//from www . j a v a 2 s . c o m import java.util.Iterator; import java.util.TreeSet; public class Main { public static void main(String[] args) { TreeSet <Integer> treeone = new TreeSet<Integer> (); TreeSet <Integer> treetwo = new TreeSet<Integer> (); treeone.add(12); treeone.add(13); treeone.add(14); treetwo.add(15); treetwo.add(16); treetwo.add(17); // adding treetwo to treeone treeone.addAll(treetwo); Iterator<Integer> iterator = treeone.iterator(); while (iterator.hasNext()){ System.out.print(iterator.next()); } } }
The code above generates the following result.