- 过滤soList中Object的Name字段为空的情况
List<Object> soList = Lists.newArrayList();List<Object> list = soList.stream().filter(item -> item.getName() != null).collect(Collectors.toList());
List<Object> soList = Lists.newArrayList()//distinct() 去重 List<Integer> maxDueDayList2 = soList.stream().map(Object::getMaxDueDay).distinct().collect(Collectors.toList());
int total = list.stream().mapToInt(User::getAge).sum();//上下等同int ageSum = userList.stream().collect(Collectors.summingInt(User::getAge));
- 计算一个List对象中某个字段的和、最大值、最小值、平均值、总个数
double doublesum = listUsers.stream().mapToDouble(Users::getAge).sum();//和
int intmax = listUsers.stream().mapToInt(Users::getAge).max().getAsInt();//最大
int intmin = listUsers.stream().mapToInt(Users::getAge).min().getAsInt();//最小
double avg = listUsers.stream().mapToDouble(Users::getAge).average().getAsDouble();//平均