I have written a small programe to
test equals and HashCode method in arrayList
public static void main(
String[] args)
{
TestVO t1 = new TestVO() ;
TestVO t2 = new TestVO() ;
ArrayList a = new ArrayList() ;
a.add(t1);
a.add(t2) ;
System.out.println("=== " + a);
a.remove(t2) ;
System.out.println("=== " + a);
}
my TestVO class is
public class TestVO {
public int hashCode()
{
return (int) (Math.random() * 100000 );
}
public boolean equals(Object o)
{
return true ;
}
}
when i run the programme i get the output
=== [com.tagLibrary.TestVO@e3f3, com.tagLibrary.TestVO@39d5]
=== [com.tagLibrary.TestVO@10b62]
it seems that when i remove an object from the list, all objects from the list is removed and again created(different hashCode).
can any one what has happened and why i am getting different hashCode .. ?