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: 
> 
> Are they overwritten so that only the last object placed in that key exists there anymore?
> 
> 
> 

Yes, assuming you're putting multiple values with the same key (according to `Object.equals`, not `Object.hashCode`.) That's specified in the [`Map.put` javadoc](http://docs.oracle.com/javase/6/docs/api/java/util/Map.html#put%28K,%20V%29):

> 
> If the map previously contained a mapping for the key, the old value is replaced by the specified value.
> 
> 
> 

If you want to map a key to multiple values, you're probably better off using something like Guava's [`ListMultimap`](https://code.google.com/p/guava-libraries/wiki/NewCollectionTypesExplained#Multimap), [`ArrayListMultimap`](http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/collect/ArrayListMultimap.html) in specific, which maps keys to lists of values. (Disclosure: I contribute to Guava.) If you can't tolerate a third-party library, then really you have to have a `Map<Key, List<Value>>`, though that can get a bit unwieldy.
The [documentation for Hashmap.put()](http://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html#put%28K,%20V%29) clearly states, "Associates the specified value with the specified key in this map. **If the map previously contained a mapping for the key, the old value is replaced**"

If you would like to have a list of objects associated with a key, then store a list as the value.

Note that 'collision' generally refers to the internal working of the HashMap, where two keys have the same hash value, not the use of the same key for two different values.