How to collect two fields of an object into the same list?
问题 I have an Object of goods, which has two properties: firstCategoryId and secondCategoryId . I have a list of goods, and I want to get all category Ids (including both firstCategoryId and secondCategoryId). My current solution is: List<Integer> categoryIdList = goodsList.stream().map(g->g.getFirstCategoryId()).collect(toList()); categoryIdList.addAll(goodsList.stream().map(g->g.getSecondCategoryId()).collect(toList())); Is there a more convenient manner I could get all the categoryIds in a