Example #1
0
  /**
   * Get a value indicating whether there is any element in the specified list matches the specified
   * predicate.
   *
   * @param <E> the type of the elements in the specified list
   * @param elements the list of elements
   * @param predicate the predicate
   * @return a value indicating whether there is any element in the specified list matches the
   *     specified predicate
   */
  public static <E> boolean anyMatch(List<E> elements, Predicate<? super E> predicate) {
    for (E element : elements) {
      if (predicate.apply(element)) {
        return true;
      }
    }

    return false;
  }
Example #2
0
  /**
   * Get the filtered list of the specified list based on the specified predicate.
   *
   * @param <E> the type of the elements in the specified list
   * @param elements the list of elements
   * @param predicate the predicate
   * @return the filtered list of the specified list based on the specified predicate
   */
  public static <E> List<E> filter(List<E> elements, Predicate<? super E> predicate) {
    List<E> results = new ArrayList<E>();

    for (E element : elements) {
      if (predicate.apply(element)) {
        results.add(element);
      }
    }

    return results;
  }