| |
9. 21. 20. The third method subSet() provides the end points: public SortedSet subSet(Object fromElement, Object toElement) |
|
if you remove something from the subset, it's gone. |
if you try to add something to the subtree, it must "fit" within your view of the tree. |
And if you add something to the original view, the subset will be altered, too. |
import java.util.Arrays;
import java.util.TreeSet;
public class MainClass {
public static void main(String args[]) throws Exception {
String elements[] = { "A", "C", "D", "G", "F" };
TreeSet set = new TreeSet(Arrays.asList(elements));
System.out.println(set.subSet("C", "F"));
}
}
|
|
[C, D] |
|