呃呃,解释一下
现在有一个集合
List<ProductInfo>
下面是属性
@Id
private String productId;//商品编码
private String productName;//商品名称
private BigDecimal productPrice;//商品单价
private Integer productStock;//商品库存
private String productDescription;//商品描述
private String productIcon;//小图
private Integer productStatus;//状态:0正常 1 下架
private Integer categoryType;//类目编码
private Date createTime;
private Date updateTime;
我现在查询出类了,集合,然后需要一个categoryType(类目编码)的集合,按照以前的想法,循环list集合,然后一个个添加,去重。其实还有更加简单的方法
List<Integer> categoryList = productInfoList.stream().map(ProductInfo::getCategoryType ).collect(Collectors.toList());
很好的一个思路,特意记下来