List<DeviceStatusDo> mergedList = Stream.concat(list2.stream(), list1.stream()) .collect(Collectors.toMap(obj -> Arrays.asList(obj.getDeviceNo(), obj.getDeviceNo(),obj.getStatus(), obj.getStatus()), Function.identity(), (obj1, obj2) -> obj1)) .values() .stream() .collect(Collectors.toList());
反转list (这样去重的话就能留下最新的数据)
Collections.reverse(collect);
collect = collect.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getDeviceNo() + ";" + o.getStatus()))), ArrayList::new));