JSONARRAY 根据某个对象的某个属性去重

JSONArray arr= JSONArray.fromObject(syxxArr.stream().filter(distinctByKey(item -> ((JSONObject)item).getString("value"))).collect(Collectors.toList()));
private static  Predicate distinctByKey(Function keyExtractor) {
   Map seen = new ConcurrentHashMap<>();
   return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}

你可能感兴趣的:(springboot,java)