I have a list of cards.
List<Map<Integer, String>>
Values ββin the list, for example,
<1, String1> <2, String2> <1, String3> <2, String4>
As a final result, I need a map>, for example
<1, <String1, String3>> <2, <String2, String4>>
How can I achieve this in Java.
THE CODE:
List<Map<Integer, String>> genericList = new ArrayList<Map<Integer,String>>(); for(TrackActivity activity : activityMajor){ Map<Integer, String> mapIdResponse = activity.getMapIdResponse(); genericList.add(mapIdResponse); }
Now this genericList is the entry to and from this list, based on the same identifiers in which I want
Map<Integer, List<String>> mapIdResponseList
Basically, to combine responses that are String based on identifiers, group the responses with the same identifier in the list, and then create a new map with this identifier as the key and list as the value.
java hashmap
Aayush
source share