Map<String,User> map = new HashMap<String,User>
map.put(user1.getTall+user1.getAge,user1);
//对每个user都做这个操作,先put进map里的user会因为后put的user的key而被覆盖
Set<String> set = map.keySet();
Iterator<String> it = set.iterator();
List<User> list = new ArrayList<User>();
while(it.hasNext())
{
list.add(map.get(it.next()));
}
大致就是这么做的了 ------解决方案-------------------- public boolean equals(Object obj){
if(obj instanceof User){
User usertest =(User)obj;
if(usertest.getAge()==age&&usertest.getHigh()==high){
return true;
}
}
return false;
}
public int hashCode(){
String age1=Integer.toString(age) ;
String high1=Integer.toString(high);
int i=Integer.parseInt(age1+high1);
return i;