private <T> Predicate<T> distinctByKeys(Function<? super T, Object> ...keyExtractors) { Map<Object, Boolean> seen = new ConcurrentHashMap<>(); return t -> { final List<?> keys = Arrays.stream(keyExtractors) .map(ke -> ke.apply(t)) .collect(Collectors.toList()); return seen.putIfAbsent(keys, Boolean.TRUE) == null; }; }
List<Map> resultMap = listMap.stream() .filter(distinctByKeys(p->p.get("invoiceCode"),p->p.get("invoiceNum"))) .collect(Collectors.toList());