A Java map that has Multi Value and supports generics?

I noticed that there is a MultiValueMap from common rights, however it does not support generics. Is there such a card?

+6
source share
3 answers

Have you tried Guava Multimap?

A collection that looks like a map, but that can associate multiple values ​​with a single key. If you call put (K, V) twice with the same key but different values, the multimap contains key mappings for both values.

Depending on the implementation, the multimap may or may not allow double key-value pairs. In other words, after adding the same key and value twice, the multimode content changes between implementations. In multi-characters that allow duplicates, the multi-map will contain two mappings, and get will return a collection that includes the value twice. In multimars that do not support duplicates, the multimap will contain one mapping from key to value, and get will return a collection that includes the value once.

http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Multimap.html

+10
source

Absolutely! Check out Google Guava Multimaps .

 Multimap<Foo, Bar> mm = new ListMultimap<Foo, Bar>(); // fill it however... Foo foo = ...; Collection<Bar> bars = mm.get(foo); 
+4
source

Guava is probably the best choice, but if you really want to stick with the Commons collection API:

http://sourceforge.net/projects/collections

Version of the popular Jakarta Commons-Collections project. All relevant classes from Commons-Collections 3.1 have been reorganized to support Java generics.

+2
source

Source: https://habr.com/ru/post/899329/


All Articles