Reputation: 83587
In Haskell, I can do
filter pred list
To create a new list with elements of list
for which the function pred
is true. Does the Java API have something similar for java.util.List
or other collections? I haven't been able to find anything in the API docs.
Upvotes: 0
Views: 261
Reputation: 932
As you maybe able to see from Java doc for List. There is no filter for core API.
I would just iterate through the list and pull whatever you need into a new list.
Upvotes: 1
Reputation: 55233
The core API does not, but Guava has Collections2.filter
, which takes a Collection
and Predicate
and returns a view of the filtered elements (which you are free to copy into a new List
).
Upvotes: 5