Apache Commons MultiMap is deprecated, what should I use now?
10,742
MultiValuedMap is the replacement and it isn't deprecated:
Defines a map that holds a collection of values against each key.
For example:
MultiValuedMap<K, String> map = new MultiValuedHashMap<K, String>(); map.put(key, "A"); map.put(key, "B"); map.put(key, "C"); Collection<String> coll = map.get(key);
It replaced MultiHashMap
Class now available as MultiValueMap in map subpackage. This version is due to be removed in collections v4.0.
and MultiValueMap:
Deprecated. since 4.1, use MultiValuedMap instead
The deprecation related to apache commons collections4 dependency jar
I think the third you meant MultiMap
was deprecated
Related videos on Youtube
Comments
-
WhiteWalker almost 2 years
Apache Commons'
MultiMap
interface with itsMultiValueMap
implementation is deprecated since version 4.1. AndMultiHashMap
seems to go entirely...What should I use as an alternative?
-
Boris the Spider over 5 yearsJust use a
Map<String, Set<String>>
. With the newMap
methods added in Java 8 these multivalued map type things are unnecessary. -
WhiteWalker over 5 yearsI used List<LinkedHashMap<String, String>> but someone told me to use MultiHashMap or its replacement for optimization. So i am confused.
-
Boris the Spider over 5 years
List<Map<...>>
is definitely not the same as any of the things you mention. They areMap<K, Collection<V>>
. -
WhiteWalker over 5 yearsSo you mean MultiValuedMap won't work the same way for List<LinkedHashMap<String, String>>
-
Boris the Spider over 5 yearsOf course not - it's a multi valued map; it supports multiple values per key. Multiple independent maps is completely different. In your use case they may serve the same purpose, but they are definitely not the same thing.
-
Mark Rotteveel over 5 yearsThose classes are not part of Java itself, so they are not deprecated with any version of Java. You should specify the full qualified name of these class so we know which library they're from.
-
Mark Rotteveel over 5 yearsHow can I check when you don't specify what classes (from which library) you are talking about? There are no classes with these names in the Java SE API, so they are not deprecated in any Java version (given they are not part of Java at all). They may be deprecated in some library, but given you give us no identifying information, we can not be sure which library.
-
-
WhiteWalker over 5 years(MultiValuedMap cannot be resolved to a type) is the error i am getting.
-
user7294900 over 5 years@WhiteWalker you can use
MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
-
WhiteWalker over 5 yearsBut what i have to import because its giving error as mentioned in MultiValuedMap and ArrayListValuedHashMap cannot be resolved.
-
user7294900 over 5 years@WhiteWalker the commons-collections4 jar: mvnrepository.com/artifact/org.apache.commons/…