public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) { Map<Object, Boolean> seen = new ConcurrentHashMap<>(); return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null; }
deviceRecords.stream().filter(distinctByKey(deviceRecord -> deviceRecord.getDeviceMac())).forEach(deviceRecord -> { System.out.println(deviceRecord.getDeviceMac()); });