zoukankan      html  css  js  c++  java
  • java8 Streams API方法总结

    一、主要方法汇总

    • 中间操作(Intermediate): 
      map (mapToInt, flatMap 等)、 filter、 distinct、 sorted、 peek、 limit、 skip、 parallel、 sequential、 unordered
    • 终端操作(Terminal): 
      forEach、 forEachOrdered、 toArray、 reduce、 collect、 min、 max、 count、 anyMatch、 allMatch、 noneMatch、 findFirst、 findAny、 iterator
    • 短路操作(Short-circuiting): 
      anyMatch、 allMatch、 noneMatch、 findFirst、 findAny、 limit

    二、中间方法:

            - filter(Predicate predicate):过滤Stream中所有不符合predicate的元素。

            - mapToXxx(ToXxxFunction mapper):使用ToXxxFunction对流中的元素执行一对一的转换,该方法返回的新流中包含了ToXxxFunction转换生成的所有元素。

            - peek(Consumer action):依次对流进行一些操作,此方法返回的流与原有流包含相同的元素。此方法主要用于调试。

            - distinct():此方法用于排序流中所有重复的元素,此方法为有状态方法。

            - sorted():对流进行排序,此方法为有状态方法。

            - limit(long maxSize):限制流中的元素个数,此方法为有状态的、短路的方法。

    三、终端方法:

            - forEach(Consumer action):遍历流中所有元素。

            - toArray():将流中所有元素转换为数组。

            - reduce():合并流中的元素。

            - min():返回流中所有元素的最小值。

            - max():返回流中所有元素的最大值。

            - count():返回流中所有元素的数量。

            - anyMatch(Predicate predicate):流中是否至少包含一个符合特定条件的元素。

            - allMatch(Predicate predicate):流中是否至少每个元素都符合特定条件。

            - noneMatch(Predicate predicate):流中是否所有元素都不符合特定条件。

            - findFirst():返回流中的第一个元素。

            - findAny():返回流中任意一个元素。

    参考链接

  • 相关阅读:
    规约先行-(六)并发处理
    MySQL选择合适的方式存储时间
    规约先行-(五)集合处理
    规约先行-(四)OOP 规约
    12.20-LaTex git workflow
    6.25-ROS 软件度量
    6.19-rosdoc_lite and 文档构建工具
    12.27-ros-decision making
    12.3-分级并发有限状态机-SMACH
    12.07-rostest学习
  • 原文地址:https://www.cnblogs.com/mithrandirw/p/8473419.html
Copyright © 2011-2022 走看看