Java tutorial
//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; } }