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
  • 100,966
  • 191
  • 140
  • 197
gogogaga
  • 175
  • 1
  • 3
  • 11

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
  • 59,313
  • 13
  • 108
  • 143
0
map.put(2, new HashMap<Integer, V>);

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