0

I would like to create an object with Map<String,Map<Integer, String>> the inner should not be a Map type because the inner key (Integer) is not a primary key (unique). And as far as I know when it comes to Map if there is a similar key value it will override the previous similar data.

What should be the datatype of my inner Map?

SCS
  • 1,162
  • 3
  • 17
  • 31

1 Answers1

0

It depends on what you are going to do with the map. If the values of the outer map are just pairs, you can use Map<String, Set<ClassContainingIntAndString>>, or if you already know what it is (like you said there are only three values?) Map<String, SomeClassThatMakesSense>. However, if you want fast access to the final Strings given the first and second Integer, you should use Map<String, Map<Integer, List<String>>> (or something similar except encapsulated in some user-defined classes, as it may be bad practice to have too many nested generics).

Alexander Wu
  • 433
  • 4
  • 8
  • The first option might work, Map>> I can do this because the inner map key is not unique – SCS Nov 14 '18 at 08:56