// 計算式(単価x数量)Function<Product,BigDecimal>calcFunction=prd->prd.getPrice().multiply(newBigDecimal(prd.getQty()));// 集約Map<String,BigDecimal>grpByTypeToSum=prdList.stream().collect(Collectors.groupingBy(Product::getProductType,Collectors.reducing(BigDecimal.ZERO,calcFunction,BigDecimal::add))...
Integer> totalByDept = employees.stream() .collect(Collectors.groupingBy(Employee::getDepartment, Collectors.summingInt(Employee::getSalary))); // Partition students into passing and failing Map<Boolean, List<Student>> passingFailing = students.stream() .collect(Collectors.partitioningBy(s -> s.getGr...
Map<Department, Integer> salariesByDept = employees.stream().collect(Collectors.groupingBy(Employee::getDepartment, summingSalaries)); 通常のリダクション操作の場合と同じく、collect()操作を並列化できるのは、該当の条件が満たされた場合だけです。部分的に蓄積された任意の結果について、その結果を空...
に似ている Collectors.partitioningBy()、使用できます Collectors.groupingBy() 以下に示すように、リストを2つのサブリストに分割します。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 //Java8以降でリストを2つのサブリストに分割する一般的な方法 public static<T> List[] split(List<T> list...
stream() .collect(Collectors.groupingBy(it -> it.getName1() + "-" + it.getName2())); System.out.println(map); // => {jiro-jiro=[Main.Name(name1=jiro, name2=jiro, name3=jiro)], saburo-saburo=[Main.Name(name1=saburo, name2=saburo, name3=saburo)], taro-taro=[Main.Name(...
Map<String, Map<String, List<Person>>> peopleByStateAndCity = personStream.collect(Collectors.groupingBy(Person::getState, Collectors.groupingBy(Person::getCity))); 型パラメータ: R - 結果の型 A - Collectorの中間蓄積の型 パラメータ: collector - リダクションを記述するCollector 戻り値:...
Integer> totalByDept = employees.stream() .collect(Collectors.groupingBy(Employee::getDepartment, Collectors.summingInt(Employee::getSalary))); // Partition students into passing and failing Map<Boolean, List<Student>> passingFailing = students.stream() .collect(Collectors.partitioningBy(s -> s.getGr...
Integer> totalByDept = employees.stream() .collect(Collectors.groupingBy(Employee::getDepartment, Collectors.summingInt(Employee::getSalary))); // Partition students into passing and failing Map<Boolean, List<Student>> passingFailing = students.stream() .collect(Collectors.partitioningBy(s -> s.getGr...
Integer> totalByDept = employees.stream() .collect(Collectors.groupingBy(Employee::getDepartment, Collectors.summingInt(Employee::getSalary))); // Partition students into passing and failing Map<Boolean, List<Student>> passingFailing = students.stream() .collect(Collectors.partitioningBy(s -> s.getGr...