Hash table manual collision handling in Java

collision, hashtable, java

Solution

Standard hash table implementations do collision handling automatically and you have no control over that. What you must do however, is to implement `hashCode()` and `equals()` for the objects used as key - but in the case of `String` / `Number`, that's also done by the standard library already. So if the task is really for you to handle collisions - then you must build your own `Map` implementation.

Problem

My task is to do a bank management system. The client accounts are kept inside the bank by using a hash table, so for each client, represented by a personal identification number, there will be an arraylist of accounts (a client can have at most 2 accounts - a saving account and a spending account). What I have to do is to manually handle the collisions that could occur. How can I do that? What method do I have to override ? I have to mention that HashTables are not my cup of tea, as I had difficulty in working with them in C. P.S. - I am planning to use HashMap as I understood is easier to work with. EDIT - Manual collision handling is THE REQUIREMENT. EDIT 2 - It comes as a requirement because the lab assistant wants us to understand how hash tables work. After more digging, I guess that I need to override the "equals" method from Hashtable, so no HashMap. Is that a correct approach? (no new ADT needed)

Original source