在使用 诸如 list001.stream().distinct().count()统计列表中不同元素的个数时,不要忘记了要重写hashCode()和equals()方法。
因为distinct()是Stream接口的方法。distinct()使用hashCode()和equals()方法来获取不同的元素。因此,我们的类必须实现hashCode()和equals()方法。
helloHKTK 2019-11-10 19:00 原文
在使用 诸如 list001.stream().distinct().count()统计列表中不同元素的个数时,不要忘记了要重写hashCode()和equals()方法。
因为distinct()是Stream接口的方法。distinct()使用hashCode()和equals()方法来获取不同的元素。因此,我们的类必须实现hashCode()和equals()方法。