i am using java and try to loop over map in ascending and descending order. i tried
NavigableMap<String, List<Person>> nm = new TreeMap<String, List<person>>();
nm.put("102", Listofperson1);
nm.put("102_104", listofperson2);
nm.put("103_102", listofperson3);
nm.put("104_105", listofperson4);
nm.put("106_107", listofperson5);
nm.put("108", listofperson6);
Sting pointer key = 103_102; Person object has Name,Id,Age
i want to sort ascending order the map by age and iterate over the map as below: 1)if ponterkey != firstkey or last key then fisrt key to pointer key map should iterate descending order of age and pointer key to last key should iterate ascending order of age.
i have tried :
NavigableMap<String, List<Person>> nmAsc = new TreeMap<String, List<person>>();
nmAsc.putAll(sortmethod(nm)) ;
NavigableMap<String, List<Person>> submapdesc = new TreeMap<String, List<person>>();
submapdesc.putAll(sortmethod(nmAsc .subMap(firstkey,true,pointerkey,false))) ;
NavigableMap<String, List<Person>> submapasc = new TreeMap<String, List<person>>();
submapdesc.putAll(sortmethod(nmAsc .subMap(pointerkey,false,lastkey,true))) ;
for (submapdesc ){}
for (submapasc ){}
sort method is correct.but when put all to the sub map it's order not working.your suggestions are highly appreciated.