import java.util.SortedSet;
import java.util.TreeSet;
import java.util.Arrays;
import java.util.Iterator;
public class SortedSetDemo {
public static void main(String[] args) {
SortedSet sortedSet = new TreeSet(Arrays.asList("one two three four five six seven eight".split(" ")));
System.out.println(sortedSet);
Object low = sortedSet.first();
Object high = sortedSet.last();
System.out.println(low);
System.out.println(high);
Iterator it = sortedSet.iterator();
for(int i = 0; i < 7; i++) {
if(3 == i)
low = it.next();
if(6 == i)
high = it.next();
else
it.next();
}
System.out.println(low);
System.out.println(high);
System.out.println(sortedSet.subSet(low, high));
System.out.println(sortedSet.headSet(high));
System.out.println(sortedSet.tailSet(low));
}
}
[eight, five, four, one, seven, six, three, two]
eight
two
one
two
[one, seven, six, three]
[eight, five, four, one, seven, six, three]
[one, seven, six, three, two]
Press any key to continue...
这是怎么算的呢?
one是第4个,two是第8个,
而那写的是(3 == i)(6 == i)啊,
就算把第一个算0,那个(6 == i) 也不应该打印出t'wo啊~~~~
疑惑ing~~~~~~