How to Reverse Values in Map <String, List<String>> Flutter?

CuriousCoder

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'] };
Shubhamhackz

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to Convert String Values From Map<String, List<String>> to type Double? Flutter

How to post a map of string and list with flutter

flutter type cast to List<Map<String, String>>

How to reverse each string in a string list at \n?

how to convert List<Map<String, String>> to Map<String, List<String>>

How to map values from List<String> into a List<Model>

How to get a value from List<Map<String, dynamic>> in Flutter

How to find a value from List<Map<String, Object>> in dart(flutter)?

dart/flutter : How to convert List of String into Map in dart

How to update any List<Map<String,dynamic>> in flutter

Get inner most values in the Map as a List in `Map<String, List<Map<String,Map<String,String>>>>` Java

How is this Map of String to String possible as a Map of String to a list of String in Groovy?

How to Convert List<Map<String, Object>> to List<Map<String, String>>

Flutter MethodChannel nested values: 'List<dynamic>' is not a subtype of type 'FutureOr<List<Map<String, double>>>'

Flutter 2: Cast List<dynamic> into List<Map<String, String>>?

how to map response to Map<String, Object> in flutter

Flutter : Compare int with list<Map<String,int>>

How to Convert a List Into Map of Map Map<String, Map<String,Object>>

How to convert a binary string to text string and the reverse in flutter?

Java Map<String,String[]> how to sum values

how to convert List<Map<String, String>> to List<Map<String, Map<String, String>>>

Flutter: How to convert list to string?

How to reverse a list of words in a shell string?

Flutter how to convert String to List<String>

How to convert String List to String in flutter?

How to convert List<String> to String in flutter

How to convert a list of java objects to Map<String, Map<String, String>>

How to add Map<String, string> into Map<String, List<Object>> in java

How to convert List<Map<String,Object>> to Map<String, String>?