1import java.util.Iterator;
2import java.util.TreeSet;
3public class TreeSetAddAllMethodExample
4{
5 public static void main(String[] args)
6 {
7 TreeSet<Integer> ts1 = new TreeSet<Integer>();
8 TreeSet<Integer> ts2 = new TreeSet<Integer>();
9 // add in TreeSet ts1
10 ts1.add(23);
11 ts1.add(24);
12 ts1.add(25);
13 // add in TreeSet ts2
14 ts2.add(26);
15 ts2.add(27);
16 ts2.add(28);
17 // add ts2 to ts1
18 ts1.addAll(ts2);
19 // create an iterator
20 Iterator<Integer> iterate = ts1.iterator();
21 // displaying the Tree set data
22 System.out.print("TreeSet values: ");
23 while(iterate.hasNext())
24 {
25 System.out.print(iterate.next() + " ");
26 }
27 }
28}