tags:

views:

1381

answers:

3

I am new to using the MultiMap interface, any help would be great.

A: 

I don't know java well enough to close this as an exact duplicate, but it appears to be the same as http://stackoverflow.com/questions/109383/how-to-sort-a-mapkey-value-on-the-values-in-java

Adam Davis
The linked question is about sorting the values of a map, this is about sorting a multimap (key -> collectionOfValues).. I think.
SCdF
A: 

Assuming your talking about this MultiMap implementation then you can't, since it returns a Collection and not a List and so doesn't support the concept of order.

If you are talking about it's implementation the MultiHashMap, then all you need to do is iterate over the keys, take the ArrayList returned and sort it using Collections.sort().

That's assuming you are using that implementation though.

There is nothing stopping you from implementing your own MultiMap fairly easily though, that supports sorting lists. It may be as easy as HashMap<K, Collection<V>>, I'm not familiar with how MultiMaps work.

SCdF
+1  A: 

Actually I don't know why you would want to sort a Map. A Map is a dictionary and you retrieve from this dictionary a (or in the case of multimaps a collection of) value(s) you're interested in.

In the case of a MultiMap you perhaps would want to sort the Collection resulting from a get. But what advantage do you have by a sorted Map since it doesn't speed up anything in finding a specific value?

boutta