Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java stream group by multiple fields

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));
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #java #stream #group #multiple #fields
ADD COMMENT
Topic
Name
7+4 =