list->map键值对映射关系:
List<Platform> platformList = platformService.listAll();
Map<Integer, String> platformMap = null;
if (platformList != null && platformList.size() > 0) {
platformMap = platformList.stream().collect(Collectors.toMap(o -> o.getId(), o -> o.getName()));
}
获取list中单个元素集合(list):
List<ProductResponse> productList = productService.query(pageNum, pageSize, startPrice, endPrice);
List<Integer> idList = productList.stream().collect(Collectors.mapping(o -> o.getId(), Collectors.toList()));
项目用到简单个人理解,不喜勿喷。欢迎留言指导。