- forEach
jsonArray.stream().forEach(jsonObject->{ JSONObject o = (JSONObject) jsonObject; //todo 操作对象 o });
- filter
- After filtration generates a new set of set
List<SysDictData> DictList = list.stream() .filter(a -> goods.getGoodsUnit().equals(a.getDictLabel())) .collect(Collectors.toList());
- List deduplication
List<GoodsSkuHistory> list = skuHistories.stream() .filter(distinctByKey(o->o.getGoodsSkuId())).collect(Collectors.toList()); /** * 去重使用 * @param keyExtractor * @param <T> * @return */ public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) { Map<Object, Boolean> seen = new ConcurrentHashMap<>(); return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null; }
java8- circulation and filtering case
Guess you like
Origin blog.csdn.net/dengdai123654/article/details/103951405
Recommended
Ranking