Question: so I've been trying to write a method that takes a HashMap, and counts how many of the same keys there are in the HashMap. So here's the code, it should be pretty self explanatory.

```
import java.util.HashMap;
import java.util.Map;

public class ExtendedHashMap extends HashMap<String, Integer> {

public ExtendedHashMap() {
    super();
}

public int keyCount(String keyString) {
    String key = keyString;
    int keyCountInt = 0;
    for(Map.Entry<String, Integer> entry : this.entrySet()) {
        if(entry.getKey() == keyString) {
            keyCountInt++;
        }
    }
    return keyCountInt;
}

public static void main(String[] args) {
    ExtendedHashMap ex = new ExtendedHashMap();
    ex.put("Item One", 5);
    ex.put("Item Three", 25);
    ex.put("Item Four", 35);
    ex.put("Item Two", 15);
    ex.put("Item One", 5);
    ex.put("Item Two", 15);
    ex.put("Item Three", 25);
    ex.put("Item Four", 35);
    System.out.println(ex.keyCount("Item One"));
}
}

```

If you run this, you'll see that it outputs one no matter what.
If you notice, the keys only have one value, so it rules out that. How can I get the the values to output as it's supposed to?

Answer: 
**Duplicate keys are not allowed in HashMap**. So it is obvious you will get only **one** as the answer!

Just for the record you will not get any Excpetion when you add two different values with same key. Your original value will silently get replaced by the new value. Try doing

```
 ex.get("Item One");

```

You may want to do the same operation on [Multimap](http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/Multimap.html).
> 
> 
> > 
> > counts how many of the same keys there are in the HashMap.
> > 
> > 
> > 
> 
> 
> 

The keys are unique in all maps. If the key is there in the Map the count will always be **ONE**
Go trough the API of [MAP](http://docs.oracle.com/javase/6/docs/api/java/util/Map.html) first.

> 
> A map cannot contain duplicate keys; each key can map to at most one
>  value.
> 
> 
> 

Also [Map.html#entrySet()](http://docs.oracle.com/javase/6/docs/api/java/util/Map.html#entrySet%28%29) returns a `java.util.Set` class which cannot contain no duplicate elements.