其他分享
首页 > 其他分享> > 获取List中的元素ID(某属性)然后返回新的List集合

获取List中的元素ID(某属性)然后返回新的List集合

作者:互联网

写法1

List<Long> stockCheckSheetIdList = stockCheckSheetPOList
                                        .stream()
                                        .map(StockCheckSheetPO::getId)
                                        .collect(Collectors.toList());

写法2

// 数组
Long[]  stockCheckProductDetailsIds = stockCheckProductDetailsPOList
                                            .stream()
                                            .map(StockCheckProductDetailsPO::getId)
                                            .toArray(Long[]::new);
// 数组转list
ArrayList<Long> arrayList = new ArrayList<Long>(stockCheckProductDetailsIds.length);
Collections.addAll(arrayList, stockCheckProductDetailsIds);

标签:stream,List,Long,getId,stockCheckProductDetailsIds,new,ID,属性
来源: https://blog.csdn.net/weixin_43991241/article/details/121441160