com.google.common.collect.TreeMultimap

For handle

Map<String,List<MyClass>> myClassListMap test2
= new HashMap<String,List<MyClass>>()

Example

myMultimap.put(&quot;Fruits&quot;, &quot;Bannana&quot;);
myMultimap.put(&quot;Fruits&quot;, &quot;Apple&quot;);
myMultimap.put(&quot;Fruits&quot;, &quot;Pear&quot;);

 

TreeMultimap t = TreeMultimap.create();

t.put('k', valueObject);

for (String k : t.keySet()){

t.get(k);

}

NOTE : when put, it will be auto sort by the valueObject ‘s Comparable.compareTo function ( this is same as java.util.TreeSet.TreeSet )

ref : http://tomjefferys.blogspot.com/2011/09/multimaps-google-guava.html

, https://avaldes.com/guava-multimap-treemultimap-implementation-example/

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s