find All from List via Predicate - Android java.util

Android examples for java.util:List

Description

find All from List via Predicate

Demo Code

/**/*from  w w w . ja  v a2s.com*/
 * Copyright (c) 2011 Loganalysis team and contributors
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   Raffael Schmid - initial API and implementation
 */
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

public class Main {
  public static <T> List<T> findAll(final List<T> list, final Predicate<T> predicate) {
    final List<T> retVal = new ArrayList<T>();
    for (final T item : list) {
      if (predicate.test(item))
        retVal.add(item);
    }
    return retVal;
  }
}

Related Tutorials