How to groupBy object properties and map to another object using Java 8 Streams?

后端 未结 4 1455
梦如初夏
梦如初夏 2021-02-19 01:02

Suppose I have a group of bumper cars, which have a size, a color and an identifier (\"car code\") on their sides.

class BumperCar {
    int size;
    String col         


        
4条回答
  •  我在风中等你
    2021-02-19 01:50

    Check out my library AbacusUtil:

    StreamEx.of(bumperCars)
             .groupBy(c -> Tuple.of(c.getSize(), c.getColor()), BumperCar::getCarCode)
             .map(e -> new DistGroup(e.getKey()._1, e.getKey()._2, e.getValue())
             .toList();
    

提交回复
热议问题