I have a List<Object>
and I want to return the first value that it finds true which matches a predicate.
I found that I can use CollectionUtils.find(collection,predicate)
(Apache commons). Assuming that the Object
contains a integer variable called : value
, how do i specify in the predicate that the value can be 1,2,3,4,5
and to discard those that dont match. Is it possible to do 'contains'.
Also not using java 8 so unable to do stream.
To return the first element in the list which matches the given predicate:
To filter the list so that it only contains elements matching the predicate:
You can notice that the
Predicate<MyObject>
is the same.