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());
        }
    }

     

    加油,愿被这世界温柔以待 ^_^
  • 相关阅读:
    C. Uncle Bogdan and Country Happiness solution
    B
    A
    Problem of Precision solution
    hdu-2255 D
    hdu1325 Is It A Tree? solution
    一体化办公系统
    dx:ASPxGridView 批量删除
    linq 多表查询出现‘查询包含对不同数据上下文上所定义项的引用。’
    DevExpress学习笔记之ASPxMenu
  • 原文地址:https://www.cnblogs.com/liruilong/p/14820805.html
Copyright © 2011-2022 走看看