I have a Map<String,Map<Integer,String>>
Sample data in this map
("aa" , ((3, "xx"),(5, "yy"),(1,"zz")))
("bb" , (5, "zz"))
Here Integer key of the inner map lies between 1 to 5. It is basically a priority number.
Now I need to fetch value for some key (say aa). It should return values from the inner map with the highest priority number (key).
In above example , yy should be returned.
Note: order of insertion of data in map has nothing to do with order of inner map's key.
What should I do -
- Use sorted inner map on the basis of key while populating map data?
- Iterate over the map with the highest priority value (5 in this case) to lowest (1 in this case)?
- Sort inner map in ascending order of key and get the last value?
aaoverride the first value? I guess it should beMap<String,List<Map<Integer,String>>>aawas just referring to adding another value to the inner map.