zoukankan      html  css  js  c++  java
  • forEachRemaining

    https://blog.csdn.net/qq_43717113/article/details/105062570

    forEachRemaining()是java1.8新增的Iterator接口中的默认方法
    对于这个方法,官方文档是这么描述的:
    Performs the given action for each remaining element until all elements have been processed or the action throws an exception. Actions are performed in the order of iteration, if that order is specified. Exceptions thrown by the action are relayed to the caller.
    简单来说,就是对集合中剩余的元素进行操作(void-T函数签名),直到元素完毕或者抛出异常。这里重要的是剩余元素,怎么理解呢。

    看看源码:

       /**
         * Performs the given action for each remaining element until all elements
         * have been processed or the action throws an exception.  Actions are
         * performed in the order of iteration, if that order is specified.
         * Exceptions thrown by the action are relayed to the caller.
         *
         * @implSpec
         * <p>The default implementation behaves as if:
         * <pre>{@code
         *     while (hasNext())
         *         action.accept(next());
         * }</pre>
         *
         * @param action The action to be performed for each element
         * @throws NullPointerException if the specified action is null
         * @since 1.8
         */
        default void forEachRemaining(Consumer<? super E> action) {
            Objects.requireNonNull(action);
            while (hasNext())
                action.accept(next());
        }
    }

     

    加油,愿被这世界温柔以待 ^_^
  • 相关阅读:
    HDU 1050 Moving Tables(贪心)
    HDU 1009 FatMouse' Trade(贪心)
    HDU 1097 A hard puzzle(快速幂)
    HDU 1016 Prime Ring Problem(dfs)
    HDU 1010 Tempter of the Bone(dfs)
    HDU 1003 Max Sum (dp)
    mysql_01 安装
    110.平衡二叉树
    1254.统计封闭岛屿的数目
    897.递归顺序查找树
  • 原文地址:https://www.cnblogs.com/liruilong/p/14820805.html
Copyright © 2011-2022 走看看