How to group by java 8 and collect ids from parent
问题 I have a class A Company { String name; Logo logo; } Logo { int color; //can have values=1 (green),2 (red),3 (blue) ... String name; String address; } Output needed : for each type 1,2,3 Group all instances of Logo by color. For each such group what were A.id Give me companies by their color logos. E.g. which companies have logo red? I tried following Input List<Company> company = {//initialization} company.stream().map(e -> e.getLogo()) .collect(Collectors.groupingBy(e -> {Logo b = new Logo(