当前位置: 代码迷 >> Java相关 >> 【求助】这个结果是怎么出来的?
  详细解决方案

【求助】这个结果是怎么出来的?

热度:465   发布时间:2006-07-24 13:53:09.0
【求助】这个结果是怎么出来的?

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~~~~~~

搜索更多相关的解决方案: 结果  

----------------解决方案--------------------------------------------------------
仍然8明白啊~~~
疑惑ing。。。。。
----------------解决方案--------------------------------------------------------
求助啊求助。。。。
----------------解决方案--------------------------------------------------------
  相关解决方案