Doxyuser
Doxyuser

Reputation: 63

how to identify duplicate keys in MultiValueMap

I have created a MultiValueMap and it has duplicate keys. I want to know how to get the list of duplicate keys and their values?

 key     value
  A        4
  A        6
  B        7
  C        1 

Upvotes: 2

Views: 3067

Answers (2)

NPKR
NPKR

Reputation: 5506

MultiValueMap Putting a value into the map will add the value to a Collection at that key. Getting a value will return a Collection, holding all the values put to that key.

getCollection(key) will return Collection of values

Upvotes: 0

amicngh
amicngh

Reputation: 7899

MultiValueMap doesn't allow duplicate keys. See below example.A MultiValueMap decorates another map, allowing it to have more than one value for a key.

 MultiValueMap lmap=new MultiValueMap();
    lmap.put("A", 4);
    lmap.put("A", 6);
    lmap.put("B", 7);
    lmap.put("C", 1);

    System.out.println("Size-->"+lmap.size());

Which results :

Size-->3

Upvotes: 2

Related Questions