java8 List一行代码解决重复数据

    技术2022-07-10  131

    1、List包含的对象去重:vehicleArchivesBeans.stream().distinct().collect(Collectors.toList());

    2、Lis根据某一属性值去重:

    List<VehicleArchivesBean> archivesBeans = vehicleArchivesBeans.stream().collect( Collectors.collectingAndThen( Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(VehicleArchivesBean::getVin))), ArrayList::new) );
    Processed: 0.018, SQL: 9