10. HashTable
HashTable
put (k,v) : 放入 (k,v)
get (k) : return v
HashSet and HashMap
若要改寫hash function計算對象,必須在class改寫equals() and hashCode()
@Override
public boolean equals (Object obj){
if (obj == null || !(obj instanceof ContactList)){
return false;
}
return new HashSet(names).equals(new HashSet(((ContactList)obj).names));
}
@Override
public int hashCode(){
return new HashSet(names).hashCode();
}
Last updated
Was this helpful?