1. TreeSet 去重
方法二
TreeSet<FileCoordinate> fcSet = new TreeSet<>(Comparator.comparing(FileCoordinate::getFilePath));
fcSet.addAll(fcList);
ArrayList<FileCoordinate> list = new ArrayList<>(fcSet);
TreeSet<FileCoordinate> fcSet = new TreeSet<>(Comparator.comparing(var -> fileCoordinate.getFilePath + ";" + fileCoordinate.getSize()));
fcSet.addAll(fcList);
ArrayList<FileCoordinate> list = new ArrayList<>(fcSet);
方法二
List<User> userList = userList.stream()
.collect(Collectors.collectingAndThen(Collectors.toCollection(
() -> new TreeSet<>(Comparator.comparing(User::getUserId))
), ArrayList::new)
);
List<User> userList = userList.stream()
.collect(Collectors.collectingAndThen(Collectors.toCollection(
() -> new TreeSet<>(Comparator.comparing(
var -> var.getUserId + ";" + var.getAge())
)
), ArrayList::new)
);