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

Share:
10,742

Related videos on Youtube

WhiteWalker
Author by

WhiteWalker

Software Engineer

Updated on June 04, 2022

Comments

  • WhiteWalker
    WhiteWalker almost 2 years

    Apache Commons' MultiMap interface with its MultiValueMap implementation is deprecated since version 4.1. And MultiHashMap seems to go entirely...

    What should I use as an alternative?

    • Boris the Spider
      Boris the Spider over 5 years
      Just use a Map<String, Set<String>>. With the new Map methods added in Java 8 these multivalued map type things are unnecessary.
    • WhiteWalker
      WhiteWalker over 5 years
      I used List<LinkedHashMap<String, String>> but someone told me to use MultiHashMap or its replacement for optimization. So i am confused.
    • Boris the Spider
      Boris the Spider over 5 years
      List<Map<...>> is definitely not the same as any of the things you mention. They are Map<K, Collection<V>>.
    • WhiteWalker
      WhiteWalker over 5 years
      So you mean MultiValuedMap won't work the same way for List<LinkedHashMap<String, String>>
    • Boris the Spider
      Boris the Spider over 5 years
      Of 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
      Mark Rotteveel over 5 years
      Those 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
      Mark Rotteveel over 5 years
      How 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
    WhiteWalker over 5 years
    (MultiValuedMap cannot be resolved to a type) is the error i am getting.
  • user7294900
    user7294900 over 5 years
    @WhiteWalker you can use MultiValuedMap<String, String> map = new ArrayListValuedHashMap<>();
  • WhiteWalker
    WhiteWalker over 5 years
    But what i have to import because its giving error as mentioned in MultiValuedMap and ArrayListValuedHashMap cannot be resolved.
  • user7294900
    user7294900 over 5 years
    @WhiteWalker the commons-collections4 jar: mvnrepository.com/artifact/org.apache.commons/…