List of usage examples for java.util.stream Collectors summarizingDouble
public static <T> Collector<T, ?, DoubleSummaryStatistics> summarizingDouble( ToDoubleFunction<? super T> mapper)
From source file:org.eclipse.collections.impl.jmh.AggregateByTest.java
@Benchmark public Map<String, DoubleSummaryStatistics> aggregateByCategory_parallel_lazy_streams_ec() { Map<String, DoubleSummaryStatistics> result = this.ecPositions.parallelStream().collect(Collectors .groupingBy(Position::getCategory, Collectors.summarizingDouble(Position::getMarketValue))); Assert.assertNotNull(result);/*w w w . ja va2 s . co m*/ return result; }
From source file:pl.prutkowski.java.playground.java8.TestCollectors.java
/** * @param args the command line arguments *///from w w w .j av a 2 s. co m public static void main(String[] args) { Map<String, Integer> monthByLen = months.stream() .collect(Collectors.toMap(String::toUpperCase, m -> StringUtils.countMatches(m, "e"))); monthByLen.forEach((month, eCount) -> System.out.println(month + " -> " + eCount)); System.out.println("---------------------------------"); Map<Object, List<String>> monthByLen2 = months.stream() .collect(Collectors.groupingBy(m -> StringUtils.countMatches(m, "e"))); monthByLen2.forEach((count, groupedMonths) -> System.out.println(count + " -> " + groupedMonths)); System.out.println("---------------------------------"); Double averageLength = months.stream().collect(Collectors.averagingDouble(String::length)); System.out.println("Average length: " + averageLength); System.out.println("---------------------------------"); Double max = months.stream().collect(Collectors.summarizingDouble(String::length)).getMax(); System.out.println("Max length: " + max); System.out.println("---------------------------------"); String reduced = months.stream().collect(Collectors.reducing((m1, m2) -> (m1 + ", " + m2))).get(); System.out.println("Reduced: " + reduced); System.out.println("---------------------------------"); System.out.println(String.join(", ", months)); System.out.println("---------------------------------"); List<String> monthsWithZ = months.stream().filter(m -> m.contains("z")).collect(new ListCollector<>()); System.out.println(monthsWithZ); }