꿉이

꿉이

꿉이꿉이· 4년

질문[JAVA] 리스트를 그룹핑해서 맵으로 변환할때 질문드립니다.

 리스트 그룹화해서 맵으로 변환하는 건 잘 되는데요... 맵 key가 String이 아닌 DTO 형태로 받고 싶은데 어떻게 해야할지 모르겠습니다.!! ㅠㅠㅠ 선배님들 도와주세요!! ㅠㅠ  [현재] Map<String, List<MenuDto>> menuList = list.stream().collect(Collectors.groupingBy(MenuDto::getParentMenu));   [ 원하는 결과 ]아래처럼 사용할 수 없을까요??? ㅠ Map< MenuDto, List<MenuDto>> = ....   toMap 이용해보고 여러가지 해보고 있는데 잘 안됩니다. ㅠㅠ Map< MenuDto, List<MenuDto>> = menuList = list.stream().collect(Collectors.toMap(Function.identity(),Collectors.groupingBy(MenuDto::getParentMenu)); . . . Map<MenuDto, List<MenuDto>> postsPerType = list.stream() .collect(Collectors.groupingBy(MenuDto::getParentMenu, () -> new Map<>(MenuDto.class), Collectors.toList()));  
1.3K
0