| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 927 人关注过本帖
标题:我真的要疯了!真心求各位看看这个是为什么?
取消只看楼主 加入收藏
believe45
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2005-12-7
收藏
 问题点数:0 回复次数:2 
我真的要疯了!真心求各位看看这个是为什么?

源程序:
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...

6 == i 怎么会打印出第8号内容呢?
我修改了一下程序,想看看i = 4,5的时候发生了什么,
源程序:
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(4 == i) {
System.out.println("4");
it.next();
}
if(5 == i) {
System.out.println("5");
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
4
5
Exception in thread "main" java.util.NoSuchElementException
at java.util.TreeMap$PrivateEntryIterator.nextEntry(TreeMap.java:1029)
at java.util.TreeMap$KeyIterator.next(TreeMap.java:1058)
at SortedSetDemo.main(SortedSetDemo.java:29)
Press any key to continue...

整个一报错了。
我看了好久都百思不得其解~~~~
哪位来帮帮偶啊~~~~~~~~~~~~~~~~~~~~~
困扰好久好久了。。。。。。。。

搜索更多相关主题的帖子: 真心 
2006-07-26 21:57
believe45
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2005-12-7
收藏
得分:0 
哦!!!!!!!!!!!!!!!!!!!!!
原来是这样~~~~~~~~~~~~~
终于搞懂了~~~~~~~~~~~~~
谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢!!!!!
:)
再次感谢~
呵呵
斑竹好人啊~~~~
2006-07-27 11:59
believe45
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2005-12-7
收藏
得分:0 
呵呵,按字典序排的么。。。。
2006-07-31 15:39
快速回复:我真的要疯了!真心求各位看看这个是为什么?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012368 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved