zoukankan      html  css  js  c++  java
  • Java--java.util.stream.Collectors文档实例

    // java.util.stream.Collectors 类的主要作用就是辅助进行各类有用的 reduction 操作,例如转变输出为 Collection,把 Stream 元素进行归组。

    public
    final class Collectors extends Object Implementations of Collector that implement various useful reduction operations, such as accumulating elements into collections, summarizing elements according to various criteria, etc. The following are examples of using the predefined collectors to perform common mutable reduction tasks: // Accumulate names into a List List<String> list = people.stream().map(Person::getName).collect(Collectors.toList()); // Accumulate names into a TreeSet Set<String> set = people.stream().map(Person::getName).collect(Collectors.toCollection(TreeSet::new)); // Convert elements to strings and concatenate them, separated by commas String joined = things.stream() .map(Object::toString) .collect(Collectors.joining(", ")); // Compute sum of salaries of employee int total = employees.stream() .collect(Collectors.summingInt(Employee::getSalary))); // Group employees by department Map<Department, List<Employee>> byDept = employees.stream() .collect(Collectors.groupingBy(Employee::getDepartment)); // Compute sum of salaries by department Map<Department, 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.getGrade() >= PASS_THRESHOLD));
  • 相关阅读:
    HasMap
    SQL Server 2005新特性之使用with关键字解决递归父子关系
    Silverlight4调用本地音频设备并将音频文件上传到服务器
    sql中exists,not exists的用法
    ie中jQuery无法解析xml文件的解决方案
    NeatUpload的安装使用
    C# 中 MSCHART 饼状图显示百分比
    JSON
    silverlight 独立存储
    SharePoint2010 自定义搜索
  • 原文地址:https://www.cnblogs.com/jsersudo/p/11453918.html
Copyright © 2011-2022 走看看