Java 8 stream to collect a Map of List of items
问题 I have a List of Maps which stores the roles and the names of people. For ex: List<Map<String, String>> listOfData 1) Role: Batsman Name: Player1 2)Role: Batsman Name: Player2 3)Role: Bowler Name: Player3 Role and Name are the Keys of the map. I want to convert this into a Map<String, List<String>> result , which will give me a list of names for each role, i.e k1: Batsman v1: [Player1, Player2] k2: Bowler v2: [Player3] listOfData .stream() .map(entry -> new AbstractMap.SimpleEntry<>(entry.get