Stream修改List的某一項的屬性,遍歷通過foreach修改list中的值。
List<ABC> list = new ArrayList<>(); list.stream().forEach(p -> p.setABCD(p.getABCD().substring(0,10)));
anyMatch()的用法
//判斷某個list中是否包含某個值
if (userInfoList.stream().map(UserInfo::getId).anyMatch(c -> c.equals(p.getCreator()))) { // }
獲取某個實體對象列表的匹配項的第一條數據:
Task first = taskList.stream().filter(x -> x.getBusinessKey().equals("aaa")).findFirst().get();
數字排序
List<Student> collect = students.stream().sorted(Comparator.comparing(Student::getMark).reversed()).collect(Collectors.toList());
//去掉reversed()表示正序,加上是倒序
獲取最大最小值
List<Double> list; Integer max = Collections.max(list); List<Double> list; Integer min = Collections.min(list);