I have a map created from a json string that is sorted in the order I need to parse in.
If there is a key at index 6 (7th key), I want to be able to iterate from this key to the end of the map and do what processing I need with these key/value pairs.
Is there anyway to do this?
A
Mapdoesn’t in general maintain an order of the keys. You’ll need to useNavigableMap, such asTreeMap. Preferable if your keys have a natural order.LinkedHashMapwhich is a map implementation which preserves the insertion order.Example snippet (LinkedHashMap):
Example snippet (TreeMap):