This is my list.

```
list = Stream.of(
        "06|20|1",
        "11|20|2",
        "11|20|2",
        "07|207|6",
        "11|207|2",
        "07|207|6",
).collect(Collectors.toList());

```

I have a hashmap such as:

```
HashMap<String, HashMap<String, String>> hashMap = new HashMap<>();
HashMap<String, String> newHash = new HashMap<>();

```

And my code is

```
for (String line : list) {
    String key, value, priority;
    key = line.split("\\|", -1)[1];
    value = line.split("\\|", -1)[0];
    priority = line.split("\\|", -1)[2];

    if (hashMap.containsKey(key)) {
        HashMap<String, String> getPriority = hashMap.get(key);
        Map.Entry<String, String> entry = getPriority.entrySet().iterator().next();
        String oldKey = entry.getKey();
        String previousPrior = getPriority.get(oldKey);
        if (Integer.parseInt(priority) > Integer.parseInt(previousPrior)) {
            getPriority.remove(oldKey);
            getPriority.put(value,priority);
           hashMap.put(key, getPriority);
        }
    } else {
        newHash.put(value, priority);
        System.out.println(newhas);
        hashMap.put(key, newhas);
    }

}

```

I want to have the have the key with highest priority only such as:

```
{20={11=2},207={07=6}}

```

as 11 and 7 has the highest valaues in 20 and 207.

But i am getting all values in the inner hashmap.