list查询重复数据

时间:2025-03-10 13:48:02
//单独String集合 List<String> list = ("a","b","a","c","d","b"); List<String> collect = ().filter(i -> i != "") // list 对应的 Stream 并过滤"" .collect((e -> e, e -> 1, Integer::sum)) // 获得元素出现频率的 Map,键为元素,值为元素出现的次数 .entrySet() .stream() // 所有 entry 对应的 Stream .filter(e -> () > 1) // 过滤出元素出现次数大于 1 (重复元素)的 entry .map(::getKey) // 获得 entry 的键(重复元素)对应的 Stream .collect(()); (collect);