guava/src/com/google/common/collect/Iterables.java
public static <T> Iterable<T> filter(
      final Iterable<T> unfiltered, final Predicate<? super T> retainIfTrue) {
    checkNotNull(unfiltered);
    checkNotNull(retainIfTrue);
    return new FluentIterable<T>() {
      @Override
      public Iterator<T> iterator() {
        return Iterators.filter(unfiltered.iterator(), retainIfTrue);
      }

      @Override
      public void forEach(Consumer<? super T> action) {
        checkNotNull(action);
        unfiltered.forEach(
            (T a) -> {
              if (retainIfTrue.test(a)) {
                action.accept(a);
              }
            });
      }

      @Override
      public Spliterator<T> spliterator() {
        return CollectSpliterators.filter(unfiltered.spliterator(), retainIfTrue);
      }
    };
  }
public static <T> Iterable<T> filter(
      final Iterable<T> unfiltered, final Predicate<? super T> retainIfTrue) {
    checkNotNull(unfiltered);
    checkNotNull(retainIfTrue);
    return new FluentIterable<T>() {
      @Override
      public Iterator<T> iterator() {
        return Iterators.filter(unfiltered.iterator(), retainIfTrue);
      }

      @Override
      public void forEach(Consumer<? super T> action) {
        checkNotNull(action);
        unfiltered.forEach(
            (T a) -> {
              if (retainIfTrue.test(a)) {
                action.accept(a);
              }
            });
      }

      @Override
      public Spliterator<T> spliterator() {
        return CollectSpliterators.filter(unfiltered.spliterator(), retainIfTrue);
      }
    };
  }
Returns a view of {@code unfiltered} containing all elements that satisfy the input predicate
{@code retainIfTrue}. The returned iterable's iterator does not support {@code remove()}.

<p><b>{@code Stream} equivalent:</b> {@link Stream#filter}.