【工具类】- 集合

集合操作

//List对象获取其中某一个属性转成 List<String>
List<String> vins = excelList.stream().map(TS::getVin).collect(Collectors.toList());

 // 去重
  List<String> disString = names.stream().distinct().collect(Collectors.toList());

集合 分组成map<key,bean>

List<OtaTaskVehicle> vehicleList = xx;
Map<Long, List<OtaTaskVehicle>> vehicleListMap = vehicleList.stream()
                .collect(Collectors.groupingBy(veh -> veh.getTaskId()));

取两个字段组成新对象

// 取两个字段组成新对象
        List<CarDTO> carDTOS = cars.stream().map
                (e -> new CarDTO(e.getCountry(), e.getName())).collect(Collectors.toList());

 (1)从List中过滤出一个元素
        Car chinaCar = ListObject.initcars().stream().filter(
                (car) -> car.getCountry().equals("中国")
        ).findAny().get();

数组转集合

List<String> vinParamList = new ArrayList<>();
Collections.addAll(vinParamList,vins);

A 集合减去B

List<String> initNumA = initNumA();
List<String> initNumb = initNumB();
List<String> diffList = initNumA.stream().filter(item -> !initNumb.contains(item)).collect(toList());

集合拆分 -guava

import com.google.common.collect.Lists;
List<List<String>> partition = Lists.partition(initNumA(), NUMBER_TWO);
posted @ 2022-08-03 14:25  爱生活(^_-)  阅读(39)  评论(0)    收藏  举报