java代码如下,输出结果中为什么s对象?
大家讲道理
大家讲道理 2017-04-18 10:48:25
0
4
1001
Collection    c2 =new ArrayList();
        Student s= new Student();
        c2.add(s);
        c2.add("我");
        Iterator it = c2.iterator();
        while (it.hasNext()) {
            it.next();
            Object object = (Object) it.next();
            System.out.println(object);
        }
输出结果为“我”,并没有s对象啊?
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(4)
阿神
while (it.hasNext()) {
            it.next(); //第一个对象 Student 
            Object object = (Object) it.next(); //第二个对象 String 
            System.out.println(object);
}

Next is executed twice once in the while loop

PHPzhong

A class that does not define the str method cannot println what you want.

小葫芦

it.next() loops twice

Ty80

it.next() loops twice!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!