function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

How to sort a map<string,list<string>> ???

Technically, you cannot sort a Map. You can, however, sort a list, so you can make a sorted list of map keys. This technique is described in this post:

It might look something like this:

Map<String, List<String>> myMap = new Map<String, List<String>>();
List<Sring> myList1 = new List<String>{'1', '2', '3'};
List<String> myList2 = new List<String>{'4', '5', '6'};
myMap.put('1', myList1);
myMap.put('2', myList2);

//Construct a list from the map keyset and sort it
List<String> keyList = new List<String>();

//Loop through the sorted keys
for (String key : keyList) {
    List<String> value = myMap.get(key);
praveen murugesanpraveen murugesan

You can't sort a map but there is a one way to store a sorted value in Map.


Map<String, List<String>> myMap = new Map<String, List<String>>();
myMap = [select ------ ----- --- from obj order by name];

So query will return a ordered value based on Name.

hey thansk for your answer

but I used wrapper class , fixed.