JDK 1.8判断集合种的元素是否存在相同

List<String> str=new ArrayList<>();

str.add("a");

str.add("a");

str.add("b");

long count=str.stream().distinct().count();//去重后,元素的个数

count<str.size()  为true  表示存在相同元素   ,flase 表没有相同元素;

也可以转set判断

posted @ 2019-02-28 15:18  夏风中的Young_Uncle  阅读(3032)  评论(0编辑  收藏  举报