Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright (C) 2010-2014, Danilo Pianini and contributors
 * listed in the project's pom.xml file.
 * 
 * This file is part of Alchemist, and is distributed under the terms of
 * the GNU General Public License, with a linking exception, as described
 * in the file LICENSE in the Alchemist distribution's top directory.
 */

import java.util.List;
import java.util.function.BiConsumer;

public class Main {
    /**
     * Facility for executing lambdas requiring access to the index. The passed
     * function will run once per element of the list. Avoid side effects on the
     * list, they won't work correctly.
     * 
     * @param <E>
     *            {@link List} data type
     * @param s
     *            the {@link List} to apply the lambda on
     * @param f
     *            the {@link BiConsumer} to apply to each element
     */
    public static <E> void forEach(final List<E> s, final BiConsumer<? super Integer, ? super E> f) {
        for (int i = 0; i < s.size(); i++) {
            f.accept(i, s.get(i));
        }
    }
}