Java Linked List .contains method -
i have linkedlist containing elements of type a. need check whether list contains element based on criteria.
is enough override .equals method in class a, or need override hash method well?
you need override hashcode() method when object used in data structures use hashes. hashmap, hashset, etc.
nothing saying must implement hashcode() function. many data structures use equals() method, not hashcode() function, can away not implementing it.
but can't guarantee nobody ever put data structure use hashcode() function, it's habit implement start.
Comments
Post a Comment