본문 바로가기
Java

[Java] List를 List를 포함한 Map으로 바꾸기

by palbokdev 2022. 11. 14.

List를 Map<K, List<V>>로 바꾸기

public Map<Integer, List<String>> getMap(List<String> strings) {
    return strings.stream().collect(
      Collectors.groupingBy(String::length, HashMap::new, Collectors.toCollection(ArrayList::new))
    );
}

 

ref : https://stackoverflow.com/questions/40772997/how-to-convert-listv-into-mapk-listv-with-java-8-streams-and-custom-list