Function<Item, List> classifier = (item) -> List.of( item.getFieldA(), item.getFieldB(), Optional.ofNullable(item.getFieldC()) ); Map<List, List<Item>> grouped = items.stream() .collect(Collectors.groupingBy(classifier));