Single element in multiple groups when grouping with stream API
问题 I'm reviewing some old code, where I'm grouping elements. It looks more or less like this: Map<Long,List<Items>> groupedItems = ... for (long groupid : groups){ for (Item item :items){ if (isGroupAccepting(item.getId(),groupid) || groupid == item.getGroup()) { groupedItems.get(groupid).add(item); } } } I planned to replace it using grouping from stream API, but I'm stuck. It works fine for my second condition, but how to deal with the first one, where item should be added to every group which