When there is a certain field in a List or several of them are the same, such data is regarded as repeated data, and the repeated data needs to be removed.
- According to a certain field deduplication, you can also use multiple fields to deduplication
List<Entity> arrays = arr.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(()
-> new TreeSet<>(Comparator.comparing(Entity :: getId))), ArrayList::new));
2. Group a field
Map<Long, List<entity>> map = arrays.stream().collect(Collectors.groupingBy(entity::getGrade));