Java Map是多值并支持泛型?

前端之家收集整理的这篇文章主要介绍了Java Map是多值并支持泛型?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我注意到公共有一个 MultiValueMap,但它不支持泛型.有这样的地图吗?

解决方法

你试过Guava的Multimap吗?

A collection similar to a Map,but which may associate multiple values with a single key. If you call put(K,V) twice,with the same key but different values,the multimap contains mappings from the key to both values.@H_403_8@

Depending on the implementation,a multimap may or may not allow duplicate key-value pairs. In other words,the multimap contents after adding the same key and value twice varies between implementations. In multimaps allowing duplicates,the multimap will contain two mappings,and get will return a collection that includes the value twice. In multimaps not supporting duplicates,the multimap will contain a single mapping from the key to the value,and get will return a collection that includes the value once. @H_403_8@

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

猜你在找的Java相关文章