0

I am using the first solution in this stackoverflow link to create and read a hashMap with 2 keys and one value .i.e

Map<Integer, Map<Integer, V>> map = //...

map.get(2).get(5);

How do I put the key/value pairs on this HashMap?

In short, I am looking to do the equivalent of

myMap.put(key, value); 

but for a multi key hashmap.

Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175
gogogaga
  • 145
  • 2
  • 10

2 Answers2

2

If you're using Java 8+, you can do (if your V type parameter is a string):

map.computeIfAbsent(2, e -> new HashMap<>()).put(5, "value");
nickb
  • 58,150
  • 12
  • 100
  • 138
0
map.put(2, new HashMap<Integer, V>);

map.get(2).put(5, "value");
maciorowsky
  • 126
  • 6