Question: I'm using a `HashMap` and I haven't been able to get a straight answer on how the `get()` method works in the case of collisions.

Let's say `n > 1` objects get placed in the same **key**. Are they stored in a `LinkedList`? Are they overwritten so that only the last object placed in that key exists there anymore? Are they using some other collision method?

If they are placed in a `LinkedList`, is there a way to retrieve that entire list? If not, is there some other built in map for **Java** in which I can do this?

For my purposes, separate chaining would be ideal, as if there are collisions, I need to be able to look through the list and get information about all the objects in it. What would be the best way to do this in **Java**? 

Thanks for all your help!

Answer: 
> 
> Let's say n > 1 objects get placed in the same key. Are they stored in a linked list? Are they overwritten so that only the last object placed in that key exists there anymore? Are they using some other collision method?
> 
> 
> 

There could be single instance for the same key so the last one overrides the prior one

```
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("a", 1);
map.put("a", 2);// it overrides 1 and puts 2 there

```

chaining comes where there turns the same hash for different keys

---

**See**

* [Java papers hash table working](http://javapapers.com/core-java/java-hashtable/)
Cite: "Let's say n > 1 objects get placed in the same key. Are they stored in a linked list? Are they overwritten so that only the last object placed in that key exists there anymore? Are they using some other collision method?" 

Yes, if the hashmap contained something under this key, it will override it. 

You can implement your own class to handle that or more simple use a HashMap> in where K is your Key Object and V the object value.
Have in mind that with last solution when you do a map.get(K) will retrieve a List or the implementation that you choose (i.e: ArrayList) so all the methods of this implementation are available for you and perhaps fulfils your requirements. For example if you used Arraylist you have the size, trimToSize, removeRange, etc.