赞
踩
stream操作写法
代码从pdf复制过来,可能有问题,可下载附件查看
List<Map<String, Object>> numberData = dataList.stream().map(obj ->
{
Map<String, Object> numberMap = new HashMap<>();
numberMap.put("name", obj.get("feeTypeName"));
numberMap.put("y", obj.get("totalNumber"));
return numberMap;
}).collect(Collectors.toList());
List<String> merNoList = respList.stream()
.map(map -> DataTran.ObjectToString(map, "merNo"))
.collect(Collectors.toList());
stream() .peek
resultList = resultList.stream()
.peek(obj -> obj.put("y", BossStringUtils.formatAmountFenToYuan(DataTran.ObjectToString(obj, "y"))))
.collect(Collectors.toList());
List<String> aa= a2mList.stream()
.map(obj -> String.valueOf(obj.get("MerNo")))
.collect(Collectors.toList());
String merNoSqlStr = a2mList
.stream()
.map(obj -> DataTran.ObjectToString(obj,"MerNo"))
.collect(Collectors.joining(","));
stream().sorted
mergedDataList =
mergedDataList.stream().sorted(Comparator.comparing(ChartsOfFee::getName)).collect(Collectors.toList());
//List<String> merNoList
String s =merNoList
.stream()
.map(merNo -> "'" + merNo + "'")
.collect(Collectors.joining(","));
stream().mapToLong().sum()
long refundAmount = list.stream().mapToLong(map -> DataTran.ObjectToLong(map, "refund_amount")).sum();
-----点评项目的应用----
List<UserDTO> userDTOS = userService.query()
.in("id", ids).last("ORDER BY FIELD(id," + idStr + ")").list()
.stream()
.map(user -> BeanUtil.copyProperties(user, UserDTO.class))
.collect(Collectors.toList());
stream().map
//Set<String> intersect
List<Long> ids = intersect.stream().map(Long::valueOf).collect(Collectors.toList());
Stream.of(1,2,3,4,5,6,7,8).skip(5).forEach(System.out::print);
stream().skip().forEach()
List<Long> ids = new ArrayList<>(list.size()); Map<String, Distance> distanceMap = new HashMap<>(list.size()); list.stream().skip(from).forEach(result -> { // 4.2.获取店铺id String shopIdStr = result.getContent().getName(); ids.add(Long.valueOf(shopIdStr)); // 4.3.获取距离 Distance distance = result.getDistance(); distanceMap.put(shopIdStr, distance); });
stream().collect(Collectors.groupingBy
Map<Long, List> map = list.stream().collect(Collectors.groupingBy(Shop::getTypeId));
http://t.csdn.cn/dOHeW
list.stream().Ũ lter(x -> x > 6).forEach(System.out::println);
Optional Ũ ndFirst = list.stream().Ũ lter(x -> x > 6).Ũ ndFirst();
boolean anyMatch = list.stream().anyMatch(x -> x > 6);
List Ũ terList = personList.stream().Ũ lter(x -> x.getSalary() > 8000).map(Person::getName)
.collect(Collectors.toList());
Optional max = list.stream().max(Comparator.comparing(String::length));// 自然排序 Optional max = list.stream().max(Integer::compareTo); // 自定义排序(从大到小排序) Optional
max2 = list.stream().max((o1, o2) -> o2 - o1);
Optional max = personList.stream().max(Comparator.comparingInt(Person::getSalary));
long count = list.stream().Ũ lter(x -> x > 6).count();
List personListNew = personList.stream().map(person -> {
Person personNew = new Person(person.getName(), 0, 0, null, null);
personNew.setSalary(person.getSalary() + 10000);
return personNew;
}).collect(Collectors.toList());
// 改变原来员工集合的方式
List personListNew2 = personList.stream().map(person -> {
person.setSalary(person.getSalary() + 10000);
return person;
}).collect(Collectors.toList());
stringList.stream().mapToInt(String::length).forEach(System.out::println);
double average = doubleList.stream().mapToDouble(Number::doubleValue).average().getAsDouble(); double
sum = doubleList.stream().mapToDouble(Number::doubleValue).sum(); double max =
doubleList.stream().mapToDouble(Number::doubleValue).max().getAsDouble();
分组合并
list.stream.collect(Collectors.toMap(User::getAge,user->user.getName(),(name1,name2)-
>name1+“,”+name2));
newMergedList.stream().sorted(Comparator.comparing(map->DataTran.ObjectToString(map,
“name”))).collect(Collectors.toList());
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。