//List集合根据条件去重 List<Project> distinctProjectList = projectList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Project :: getProjectAreaId))), ArrayList::new)); //List集合排序 (正序) List<Order> newList = list.stream().sorted(Comparator.comparingDouble(Order::getId)).collect(Collectors.toList()); //List集合排序 (倒序) List<Order> newList = list.stream().sorted(Comparator.comparingDouble(Order::getId).reversed()).collect(Collectors.toList());
int i = 5; //截取List集合中前 i 个元素 List<Order> newList1 =list.stream().limit(i ).collect(Collectors.toList()); //越断List集合中最后的 i 个元素 List<Order> newList2 = (newList.stream().skip(i ).collect(Collectors.toList()));
List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd", "", "jkl"); //List集合去除空字符串 List<String> filtered = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList()); // 获取空字符串的数量 int count = (int) strings.stream().filter(String::isEmpty).count();
//取Double的List聚合中的最大值 Double max = taxList.stream().max(Comparator.comparing(Double::doubleValue)).get(); //拿对象中某个字段比较最大值 ZfastCustomerOrder info = zfastCustomerOrderList.stream().max(Comparator.comparing(ZfastCustomerOrder::getTaxRate)).get();
//根据条件去除元素 teaTeaching1.removeIf(filter -> filter.deleteById(teaTeachingOld.getTeacherId()));
//根据条件过滤元素 List<ProjectsScheduleExportVO> projectScheduleListI = projectScheduleList.stream().filter(o -> o.getScheduleType().equals("I") ).collect(Collectors.toList());