检查list集合中是否存在某个值
if (tagList.stream().anyMatch(tag -> tag.getTagId() == 4012)) {
continue;
}
将对象List中的某个字段放到新的List中
List<Long> sourceId = itemModels.stream().map(FeedStreamItemModel::getSourceId).collect(Collectors.toList());
List 集合的根据对象中的某个字段进行排序
List<DestImage> destImageList = Lists.newArrayList(images.values());
destImageList = destImageList.stream().sorted(Comparator.comparing(DestImage::getBookElementOrder)).collect(Collectors.toList());
list 转 map
// (key1, key2) -> key2) 这个是指键相同进行替换的
Map<Long, FeedStreamCommentModel> commentModelMap = commentModelList.stream().collect(Collectors.toMap(FeedStreamCommentModel::getSourceId, Function.identity(), (key1, key2) -> key2));
计算一个List对象中某个字段总和
int total = list.stream().mapToInt(User::getAge).sum();
持续更新…