Take the 2-minute tour ×

I have a guava HashMultimap like this

Multimap<String, String> multiMap = HashMultimap.create();
multiMap.put("a", "x");
multiMap.put("a", "y");
multiMap.put("b", "y");
multiMap.put("b", "z");
multiMap.put("d", "x");
multiMap.put("c", "h");

and I want to create a table with the distinct key and values. Calling

multiMap.values(); // returns x,y,y,z,x,h

but I want to the distinct set of values?.

I'm aware that Iterator.filter() is available but am unsure how it should be implmented. The expected result should be

// x,y,z,h
share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

I'd just use


or, if you want an immutable version:


Note that in either case you no longer have a live view of the values but a copy.

share|improve this answer
All correct but method designed to get multimap values is called values(), not getValues(). –  Xaerxess Mar 7 '12 at 15:16
Updated, thanks. –  Paul Blessing Mar 8 '12 at 3:13
add comment

Your Answer


