代码:
public class A {
public static void main(String[] args) {
SortedSet st = new TreeSet(Arrays.asList("one two tree four five six seven eight".split(" ")));
Object low = st.first(),
high = st.last();
Iterator it = st.iterator();
for(int i = 0;i < 6;i++){
if(i ==3)
low = it.next();
if(i == 6)
high = it.next();
else it.next();
}
System.out.println(low);
System.out.println(high);
}
}
为什么结果是:one two而不是one tree
java TreeSet问题
答案:2 悬赏:60 手机版
解决时间 2021-03-15 19:41
- 提问者网友:夢醒日落
- 2021-03-15 09:04
最佳答案
- 五星知识达人网友:举杯邀酒敬孤独
- 2021-03-15 10:38
public class A {
public static void main(String[] args) {
SortedSet<String> st = new TreeSet<String>(Arrays.asList("one two tree four five six seven eight".split(" ")));
Object low = st.first(),
high = st.last();
System.out.println(st);
Iterator<String> it = st.iterator();
for(int i = 0;i < st.size();i++){
if(i ==3)
low = it.next();
else if(i == 6)
high = it.next();
else it.next();
}
System.out.println(low);
System.out.println(high);
}
}
public static void main(String[] args) {
SortedSet<String> st = new TreeSet<String>(Arrays.asList("one two tree four five six seven eight".split(" ")));
Object low = st.first(),
high = st.last();
System.out.println(st);
Iterator<String> it = st.iterator();
for(int i = 0;i < st.size();i++){
if(i ==3)
low = it.next();
else if(i == 6)
high = it.next();
else it.next();
}
System.out.println(low);
System.out.println(high);
}
}
全部回答
- 1楼网友:洒脱疯子
- 2021-03-15 11:00
因为在 if(i ==3)
low = it.next();
时,你让it.next();又前进了一步~但是你的i却没有立刻++
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯