public static List<String> getDuplicateElements(List<Dept> list, boolean flag) {
        return list.stream() //
                .map(e -> { // 获取deptCode或deptAlias的Stream
                    return flag ? e.getDeptCode() : e.getDeptName();
                }).collect(Collectors.toMap(e -> e, e -> 1, (a, b) -> a + b)) // 获得元素出现频率的 Map,键为元素,值为元素出现的次数
                .entrySet().stream() // 所有 entry 对应的 Stream
                .filter(entry -> entry.getValue() > 1) // 过滤出元素出现次数大于 1 的 entry
                .map(entry -> entry.getKey()) // 获得 entry 的键(重复元素)对应的 Stream
                .collect(Collectors.toList()); // 转化为 List
    }

 

相关文章:

  • 2022-02-13
  • 2022-12-23
  • 2021-11-07
  • 2022-12-23
  • 2021-06-16
  • 2022-12-23
  • 2021-11-30
猜你喜欢
  • 2021-08-04
  • 2021-07-29
  • 2022-12-23
  • 2021-10-17
  • 2021-07-06
  • 2022-12-23
  • 2021-10-25
相关资源
相似解决方案