stream()根据List<Map<String, Object>> Map key去重

List<Map<String, Object>> vin = list.stream().filter(distinctByKey(o -> o.get(“vin”))).collect(Collectors.toList());

public static Predicate distinctByKey(Function<? super T, Object> keyExtractor) {
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}

猜你喜欢

转载自blog.csdn.net/weixin_43524361/article/details/112859622