美文网首页
JAVA8新特性lambda表达式(优雅的去重)

JAVA8新特性lambda表达式(优雅的去重)

作者: 不见当年三月花 | 来源:发表于2019-07-27 18:12 被阅读0次
    字符串去重
    List<String> dataList = list.stream().distinct().collect(Collectors.toList());
    
    
    对象属性去重
    //根据getName去重
    personList = personList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(
                    () -> new TreeSet<>(Comparator.comparing(Person::getName))), ArrayList::new));
    
    

    相关文章

      网友评论

          本文标题:JAVA8新特性lambda表达式(优雅的去重)

          本文链接:https://www.haomeiwen.com/subject/mtnerctx.html