4

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?

WhiteWalker
  • 365
  • 2
  • 5
  • 14
  • 2
    Just use a `Map>`. With the new `Map` methods added in Java 8 these multivalued map type things are unnecessary. – Boris the Spider Dec 30 '18 at 08:15
  • I used List> but someone told me to use MultiHashMap or its replacement for optimization. So i am confused. – WhiteWalker Dec 30 '18 at 08:25
  • `List>` is definitely not the same as any of the things you mention. They are `Map>`. – Boris the Spider Dec 30 '18 at 08:27
  • So you mean MultiValuedMap won't work the same way for List> – WhiteWalker Dec 30 '18 at 08:33
  • 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. – Boris the Spider Dec 30 '18 at 08:37
  • 2
    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 Dec 30 '18 at 08:44
  • 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. – Mark Rotteveel Dec 30 '18 at 10:22

1 Answers1

8

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

Ori Marko
  • 56,308
  • 23
  • 131
  • 233