public boolean equals(Object o)
{
V v=(V)o;
System.out.println(v.getI()==this.i);
return v.getI()==this.i;
}
public int compareTo(Object o){
V v=(V)o;
if (v.getI()> this.i)
return -1;
else if(v.getI() <this.i)
return 1;
return 0;
}
}
public class Test{
public static void main(String[] args)
{
HashSet set=new HashSet();
for(int i=0; i <10; i++)
set.add(new String(“test”));
System.out.println(set.size());
for (int i=0; i <10; i++)
{set.add(new V(1));}
System.out.println(set.size());
}
} 作者: 韩新凯 时间: 2012-5-11 22:10
public int hashCode()
{
return name.hashCode()+age*34;
}