lambda过滤空值、转字符串

根据属性过滤
List successList = orderLists.stream().filter(item -> item.getOrderStatus() == OrderStatusEnum.PAY_SUCCESS.getStatus()).collect(Collectors.toList());
提取集合中的属性值
List attrValIds = skuAttrs.stream().sorted().map(attr -> attr.getAttrValId()).collect(Collectors.toList());
productAttrValueDTOS.stream().map(ProductAttrValueDTO::getName).collect(Collectors.joining(","));
List tagsList = Arrays.asList("a", "b", null);
//过滤掉空值
List listWithoutNulls = tagsList.stream()
        .filter(Objects::nonNull)
        .collect(Collectors.toList());
//过滤空值并且逗号分隔转字符串
String tags = tagsList.stream()
        .filter(Objects::nonNull)
        .collect(Collectors.joining(","));
System.out.println(tags);
复制代码

转载于:https://juejin.im/post/5d25b307f265da1ba2528816

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