How to convert List into Map>, with Java 8 streams and custom List and Map suppliers?

前端 未结 3 533
自闭症患者
自闭症患者 2020-11-30 03:55

It\'s easy to convert List into Map>. For example:

public Map> ge         


        
3条回答
  •  孤街浪徒
    2020-11-30 04:29

    I had a similar situation. I solved it like:

    Map> map = stringList.stream().collect(Collectors.toMap(str -> str, str -> populateList(str)));
    

    And populateList() is:

    private List populateList(final String str) {
        ...
        ....
        List list = // dao.get(str);
        return list;
    }
    
        

    提交回复
    热议问题