Iterator it = a1.iterator();
while(it.hasNext())
{
Person p = (Person)it.next();
String name = p.getName();
int age = p.getAge();
System.out.println("name: "+name+" "+"age: "+age);
}
}
public static ArrayList singleElements(ArrayList list)
{
ArrayList ls = new ArrayList();
Iterator it = list.iterator();
while(it.hasNext())
{
Object obj = it.next();
if(!ls.contains(obj))
ls.add(obj);
}
return ls;
}
}
class Person
{
private String name;
private int age;
public Person(String name,int age)
{
this.name = name;
this.age = age;
}
public String getName()
{
return name;
}
public int getAge()
{
return 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;
}
}