java8list集合使用lambad表达式

1.根据对象的属性过滤list集合

 List<RespGoodsVo> list = cabinetLockerGridService.queryGoodsByLocker(lockerId);
 List<RespGoodsVo> filterList = list.stream().filter(goods -> Integer.parseInt(goods.getNum()) > 0).collect(Collectors.toList());

2.lambad表达式里调用方法 将集合中每一个用户加1分

public void updateScoreEveryMonth() {
		List<CabinetUserScoreEntity> userList= cabinetUserScoreService.getAllUserScore();
		userList.stream().forEach(user->updateScore(user,1));
	}
private void updateScore(CabinetUserScoreEntity user, int monthNum) {
		int score = user.getScore();
		user.setScore(score+monthNum);
		cabinetUserScoreService.update(user);
	}
发布了47 篇原创文章 · 获赞 5 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_37460672/article/details/99609616