while(it.hasNext())
{
Person p = (Person)it.next();
sop(p.getName()+"::"+p.getAge());
}
}
}
class Person
{
private String name;
private int age;
Person(String name,int age)
{
this.name = name;
this.age = age;
}
public int hashCode()如果没有覆盖hashCode方法则不会运行equals方法,因为对象已经用自己的hashCode开辟了存储空间,就没必要在进行equals比较了
{
System.out.println(this.name+"....hashCode");
return 60;
}
public boolean equals(Object obj)
{
if(!(obj instanceof Person))
return false;
Person p = (Person)obj;
System.out.println(this.name+"...equals.."+p.name);