As you suggested I have tried to override the equals and hashcode method....No Idea how to override the equals method properly....
But Still its not working for me....I have pasted some sample code here
public class Risking
{
String empcode;
String name;
public String getEmpcode() {
return empcode;
}
public void setEmpcode(String empcode) {
this.empcode = empcode;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Risking(String empcode, String name)
{
this.empcode = empcode;
this.name = name;
}
public boolean equals(Object obj)
{
if(obj==null)
return false;
String s= (String)obj;
return s.equals(empcode);
}
public int hashCode()
{
final int PRIME = 31;
int result = 1;
result = PRIME * result + empcode.hashCode();
return result;
}
public static void main(String args[])
{
ArrayList aList = new ArrayList();
Risking r1 = new Risking("117","Rocky");
Risking r2 = new Risking("118","Vicky");
aList.add(r1);
aList.add(r2);
System.out.println(aList.contains("117"));
}