stream:app
集合分組:spa
Map<String, List<Student>> collect = list.stream().collect(Collectors.groupingBy(Student::getSex));ci
集合取出某一屬性方法:get
List<String> tableNames=list.stream().map(User::getMessage).collect(Collectors.toList());
集合過濾filter:table
//過濾出符合條件的數據 List<Apple> filterList = appleList.stream().filter(a -> a.getName().equals("香蕉")).collect(Collectors.toList());
求和:email
BigDecimal totalMoney = appleList.stream().map(Apple::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
Map轉List:stream
//郵箱集合 List<String> emails = bossCandyGrantBO.getMatchEmail().entrySet() .stream().map(entry->entry.getKey()).collect(Collectors.toList()); //設置匹配郵箱入參 MatchUserNoRequest matchEmailUserNoRequest = new MatchUserNoRequest(emails,MatchUserNoRequest.matchEmail); //批量查詢匹配的郵箱 List<MatchUserNoBO> emailUserNos = memberQueryService.queryMatchEnableUserNo(matchEmailUserNoRequest); //循環遍歷存入Map bossCandyGrantBO.getMatchEmail().forEach((k,v)->{ emailUserNos.stream() .filter(o->o.getEmail().equals(k)) .findFirst().ifPresent(o->userAmountBOList.add(new MatchUserAmountBO(o.getUserNo(),new BigDecimal(v)))); });