Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi Key Multi Value map possible?

I see there is a Multimap that allows duplicate values for a key http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/Multimap.html

I also noticed guava has a Table which allows multiple keys, but not duplicated values. http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/Table.html

I can't find anywhere where there is a "Table" that allows duplicated values, or a "Multimap" that allows multiple keys.

Is this something that exists already, or would I have to implement this myself?

I just want to implement a Multimap with 2 keys i.e. <K1, K2, Value>

like image 347
Brandon Ling Avatar asked Nov 27 '25 05:11

Brandon Ling


2 Answers

There's nothing I'm aware of that supports that need. However, it's not terribly difficult to just e.g. use a Multimap<MyK1AndK2Pair, Value> where you write a custom pair class yourself, or conversely to use a Table<K1, K2, List<Value>> and manage things yourself.

like image 100
Louis Wasserman Avatar answered Nov 28 '25 22:11

Louis Wasserman


What about nested maps?

Multimap<K1, Multimap<K2, Value>> doubleMultiMap = new HashMultiMap<>();
like image 39
wbars Avatar answered Nov 28 '25 20:11

wbars



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!