I am going through the code which uses Predicate in Java. I have never used Predicate. Can someone guide me to any tutorial or conceptual explanati
Adding up to what Micheal has said:
You can use Predicate as follows in filtering collections in java:
public static Collection filter(final Collection target,
final Predicate predicate) {
final Collection result = new ArrayList();
for (final T element : target) {
if (predicate.apply(element)) {
result.add(element);
}
}
return result;
}
one possible predicate can be:
final Predicate filterCriteria =
new Predicate() {
public boolean apply(final DisplayFieldDto displayFieldDto) {
return displayFieldDto.isDisplay();
}
};
Usage:
final List filteredList=
(List)filter(displayFieldsList, filterCriteria);