Is there a Java 1.5 equivalent to the Predicate<T> methods in .Net?
问题 Specifically, I'm looking for similarly clean notation to the Collection<T>.TrueForAll / Exists , etc. It feels smelly to have to write a foreach loop to inspect the return of a method on each object, so I'm hoping there's a better Java idiom for it. 回答1: Predicates are provided in the Google Collections library. 回答2: Functional Java provides first-class functions. A predicate is expressed as F<T, Boolean> . For example, here's a program that tests an array for the existence of a string that