If I want to check that the value present at first index position in a TreeMap is xyz then do xyz Else if the value present at the first index position is abc then do abc. How I will be able to write this? Because I want to access arranged indices in a TreeMap. I want to access sorted keys of a TreeMap one by one in order. Help required
TreeMap Sorted Positions Access
203 Views Asked by Ammarah At
2
There are 2 best solutions below
1
On
The quickest and ugliest hack might simply be
List<KeyType> keyList = new ArrayList<>(myTreeMap.keySet());
KeyType nthKey = keyList.get(nthIndex);
but I'd be asking myself why am I using a TreeMap in the first place, when I want to look up entries by index? Would it be more efficient to use a List and call sort?
Edit
Edit2