//List<User> list = new ArrayList<User>();

一、泛型里属性计算求和

var sumVal = list.stream()
                .filter(u -> u.getName().startsWith("haha"))
                .map(u -> u.getAge() + u.getId())
                .mapToLong(Long::longValue).sum();

二、泛型里属性求和

var sumAge = list.stream()
                .filter(u -> u.getName().startsWith("haha"))
                .mapToInt(User::getAge).sum();

三、泛型过滤

var list2 = list.stream()
                .filter(u -> u.getName().startsWith("haha")).collect(Collectors.toList());

四、commons-collections介绍

博客:https://www.cnblogs.com/myitnews/p/12289816.html
官链:https://commons.apache.org/proper/commons-collections/

相关文章:

  • 2022-02-05
  • 2022-12-23
  • 2022-12-23
  • 2022-02-19
  • 2021-10-15
  • 2021-05-25
  • 2021-12-26
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
  • 1970-01-01
  • 2022-01-13
  • 2022-03-10
相关资源
相似解决方案