获取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);

上一篇:从list集合中抽取getId转为新的集合


下一篇:java多线程使用方法之一