@NonNull static fun <A : Any!> filter(@NonNull iterable: MutableIterable<A>, @NonNull predicate: Predicate<in A>): MutableIterable<A>
Returns an iterable consisting only of elements that satisfy the given predicate. As the method is working directly with iterables it needs to create one, thus it returns an ArrayList
as an Iterable
. If you want to get a different type please use Iterables#filter(Iterable, Supplier, Predicate)
method instead.
iterable
- MutableIterable<A>: elements that should be filtered
predicate
- Predicate<in A>: predicate that elements needs to satisfy
- type of the elements of the given iterable
Return
MutableIterable<A>: iterable containing only elements that satisfied the predicate.
@NonNull static fun <A : Any!, C : MutableCollection<A>!> filter(@NonNull iterable: MutableIterable<A>, @NonNull supplier: Supplier<out C>, @NonNull predicate: Predicate<in A>): C
Returns an iterable consisting only of elements that satisfy the given predicate. It is possible to specify the type of Iterable
that should be returned.
iterable
- MutableIterable<A>: elements that should be filtered
supplier
- Supplier<out C>: supplier capable of returning the resulting iterable
predicate
- Predicate<in A>: predicate that elements needs to satisfy
- type of the elements of the given iterable
- Type of collection to be returned
Return
C: collection containing only elements that satisfied the predicate.