import java.util.*;
public class TestIterator {
public static void main(String []args) {
Name name1 = new Name("n1","f1");
Name name2 = new Name("n2","f2");
Name name3 = new Name("n3","f3");
Collection c = new HashSet();
Iterator i = c.iterator();
c.add(name1);
c.add(name2);
c.add(name3);
while (i.hasNext()) {
Name name = (Name)i.next();
String firstName = name.firstName;
System.out.println(firstName + "");
}
}
}
class Name {
public String firstName;
public String lastName;
Name(String firstName,String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
}
编译通过了,运行时没有任何的输出,我明明是用了System.out.println(),这是为什么