import java.util.*;
class Person
{
private String name;
private int age;
Person(String name,int age)
{
this.name = name;
this.age = age;
}
public boolean equals(Object obj)
{
if(!(obj instanceof Person))
return false;
Person p = (Person)obj;
System.out.println(this.name+"======="+p.name);
return this.name.equals(p.name) && this.age == p.age;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
}
class Noname9
{
public static void main(String[] args)
{
ArrayList al = new ArrayList();
al.add(new Person("zhangsan01",31));
al.add(new Person("zhangsan01",31));
al.add(new Person("zhangsan03",32));
al.add(new Person("zhangsan05",34));
al.add(new Person("zhangsan05",34));
Iterator it = al.iterator();
while(it.hasNext())
{
Person p = (Person) it.next();
sop("name: "+p.getName()+"--"+"age: "+p.getAge());
}
}
public static void sop(Object obj)
{
System.out.println(obj);
}
}
|