I have
Map<String,List<String>> myMap = {'1': ['A','B','C'], '2': ['D','E','F'], '3': ['G','H','I'] };
I would like to know how I can reverse the list values. This is what I want to achieve:
Map<String,List<String>> myMap = {'1': ['C','B','A'], '2': ['F','E','D'], '3': ['I','H','G'] };
You can do it like this :
void main() {
Map<String,List<String>> myMap = {'1': ['A','B','C'], '2': ['D','E','F'], '3': ['G','H','I'] };
Map<String,List<String>> reversedMap = {};
myMap.forEach((key,value) {
reversedMap[key] = value.reversed.toList();
});
print(reversedMap);
}
OUTPUT :
{1: [C, B, A], 2: [F, E, D], 3: [I, H, G]}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments