add TreeSet(Collection) constructor

This commit is contained in:
Joel Dice 2011-01-20 09:39:16 -07:00
parent 0ca7ed8c67
commit 3aff7dc861
2 changed files with 18 additions and 0 deletions

View File

@ -33,6 +33,14 @@ public class TreeSet<T> extends AbstractSet<T> implements Collection<T> {
}
});
}
public TreeSet(Collection<? extends T> collection) {
this();
for (T item: collection) {
add(item);
}
}
public Iterator<T> iterator() {
return new MyIterator<T>(set.first());

View File

@ -1,6 +1,8 @@
import java.util.Comparator;
import java.util.TreeSet;
import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Iterator;
@ -87,5 +89,13 @@ public class Tree {
map.put("y", "Y");
isEqual(printMap(map), "a=A, b=B, c=C, q=Q, y=Y, z=Z");
Collection<Integer> list = new ArrayList<Integer>();
list.add(7);
list.add(2);
list.add(9);
list.add(2);
isEqual(printList(new TreeSet<Integer>(list)), "2, 7, 9");
}
}