java - logic from SCJP book related to Collections -


public class person {      private string name;      public person(string name) {         this.name = name;     }     public int hashcode() {         return 420;     } } 

based on above program answer is:

answer: time find value hashmap person key depends on size of map.

i have no clue/idea how come answer above. thought wrong hashcode() method implementation options follows:

  • which statement true?
  • a. time find value hashmap person key depends on size of map.
  • b. deleting person key hashmap delete map entries keys of type person.
  • c. inserting second person object hashset cause first person object removed duplicate.
  • d. time determine whether person object contained in hashset constant , not depend on size of map.

answer: a

if can provide understanding on same great won't able find answers on net this

hashmap uses hashcode place entries in bucket , equals locate them. if entries have same hashcode end in same bucket. whenever request map , hashmap go through entries same bucket , call equals on each entry find 1 requested you. that's why

the time find value hashmap person key depends on size of map.

is correct answer