美文网首页
解决使用 lambda 表达式不能使用 获取 index 的问题

解决使用 lambda 表达式不能使用 获取 index 的问题

作者: 程序猿_小刚 | 来源:发表于2018-06-04 10:39 被阅读0次
/**
 * Iterable 的工具类
 * @author mazg
 *
 */
public class Iterables {
    
    public static <E> void forEach(Iterable<? extends E> elements,BiConsumer<Integer,? super E> action){
        Objects.requireNonNull(elements);
        Objects.requireNonNull(action);
        int index = 0;
        for (E element : elements) {
            action.accept(index++, element);
        }
    }
}

相关文章

网友评论

      本文标题:解决使用 lambda 表达式不能使用 获取 index 的问题

      本文链接:https://www.haomeiwen.com/subject/nweesftx.html