Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Iterator;
import java.util.function.Predicate;

public class Main {

    public static <T> T removeFrom(Iterable<T> collection, Predicate<T> predicate) {
        Iterator<T> it = collection.iterator();

        while (it.hasNext()) {
            T o = it.next();

            if (predicate.test(o)) {
                it.remove();
                return o;
            }
        }

        return null;
    }
}