java8 实现提取List对象中的属性提取到新List中

  • Post author:
  • Post category:java


List<String> names = userList.stream().map(User::getName).collect(Collectors.toList());

根据多个字段属性来给List去掉重复值

List<Xxx> distinctList = rowList.stream()
        .collect(Collectors.collectingAndThen(
                Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(obj -> String.join("-", obj.getA(), obj.getB(), obj.getC())))),
                ArrayList::new
        ));



版权声明:本文为weixin_42272558原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。