Take the 2-minute tour ×

Has anybody used TreeMultimap in Google Collections? I understand that with a TreeMultimap, its keys and values are ordered by their natural ordering or by supplied comparators. I was wondering if there is a function that allows user to supply a key and returns all the values whose keys are greater than the user-supplied key. This can be done with a SortedMap in Java which has a function called tailMap. Thanks!

share|improve this question
add comment

2 Answers

up vote 9 down vote accepted

I haven't used the TreeMultiMap class but a quick look at the Javadoc would suggest that you could use the asMap() method to get a SortedMap and then call tailMap() on that.

share|improve this answer
I haven't used TreeMultiMap either, but this certainly looks like the correct solution. +1 –  Jonik Nov 6 '09 at 15:31
Thanks a lot, I think this is the correct solution. –  flyingfromchina Nov 6 '09 at 16:12
add comment

Yeah, I made TreeMultimap.asMap() return a SortedMap to support cases like this.

Remember that tailMap() returns all entries whose keys are greater than or equal to the provided key. The original question said just "greater than".

share|improve this answer
It doesn't get more authoritative than an answer from the author. –  kris Aug 29 '13 at 1:57
add comment

Your Answer


