标红的是出现的问题,怎么解决……?
class Demo2
{
public static void main(String[] args)
{
Collection c=new ArrayList();//找不到符号
Person p=new Person();
p.name="小丽";
p.sex="女";
p.age=14;
Person p1=new Person();
p1.name="小红";
p1.sex="女";
p1.age=17;
Person p2=new Person();
p2.name="小明";
p2.sex="男";
p2.age=20;
c.add(p);
c.add(p1);
c.add(p2);
Iterator it=c.iterator();//找不到符号
while(it.hasNext())
{
Object obj=(it.next());
System.out.println(obj.toString());
}
}
}
class Person
{
String name;
String sex;
int age;
public String toString()
{
return name+" "+age+" "+sex;
}
}
|