treeset add all code example
Example: TreeSet addAll() method in java
import java.util.Iterator;
import java.util.TreeSet;
public class TreeSetAddAllMethodExample
{
public static void main(String[] args)
{
TreeSet<Integer> ts1 = new TreeSet<Integer>();
TreeSet<Integer> ts2 = new TreeSet<Integer>();
ts1.add(23);
ts1.add(24);
ts1.add(25);
ts2.add(26);
ts2.add(27);
ts2.add(28);
ts1.addAll(ts2);
Iterator<Integer> iterate = ts1.iterator();
System.out.print("TreeSet values: ");
while(iterate.hasNext())
{
System.out.print(iterate.next() + " ");
}
}
}