0

Recently I started using Apache Commons MultiKeyMap for some of my projects and in there I can have multiple values for a value.

MultiKeyMap typePanelUnoMap = new MultiKeyMap();

I want to know whether we can preserve insertion order when using MultiKeyMap. I know that java.util.LinkedHashMap can preserve the insertion order.

Map hshmap = new LinkedHashMap()

Can I have the same functionality with MultiKeyMap?

Thanks,
Keth

Abra
  • 19,142
  • 7
  • 29
  • 41
keth
  • 793
  • 2
  • 11
  • 36

2 Answers2

2

from the javadocs

This map is implemented as a decorator of a AbstractHashedMap which enables extra behaviour to be added easily.

MultiKeyMap.decorate(new LinkedMap()) creates an ordered map.

Ajay George
  • 11,759
  • 1
  • 40
  • 48
0

Since Apache Commons Collections 4, method multiKeyMap is being used instead of method decorate.

So it should be:

MultiKeyMap<String, Object> multiKeyMap= MultiKeyMap.multiKeyMap(new LinkedMap<>());
Abra
  • 19,142
  • 7
  • 29
  • 41
KushkiN
  • 1
  • 1