tripleblep
tripleblep

Reputation: 540

Check for number of values in a key using Multimap

I'd like to check if there are a certain number of values for a given key within a Multimap. How would I go about doing this?

Upvotes: 0

Views: 1935

Answers (2)

Kevin Bourrillion
Kevin Bourrillion

Reputation: 40851

Either multimap.get(key).size() or multimap.keys().count(key) will work. If it matters, the first will probably "waste" an object instance and the second will probably not.

Upvotes: 4

Francisco Spaeth
Francisco Spaeth

Reputation: 23903

you can perform a get(key) that will return a collection, over that collection you invoke size() to find out how many elements are on the Multimap associated with the given key.

From the documentation:

Collection get(K key) Returns a collection view of all values associated with a key.

Upvotes: 2

Related Questions