You can use collective collectionsCollectionUtils from Apache :
List<Integer> primes = Arrays.asList(3, 5, 7, 11, 13)
CollectionUtils.exists(primes, even);
Where evenis the predicate:
Predicate even = new Predicate() {
public boolean evaluate(Object object) {
return ((Integer)object) % 2 == 0;
}
}
Or in the embedded version:
List<Integer> primes = Arrays.asList(2, 3, 5, 7, 11, 13)
CollectionUtils.exists(primes, new Predicate() {
public boolean evaluate(Object object) {
return ((Integer)object) % 2 == 0;
}
});
Yes he ugly for two reasons:
- Java , .
commons-collections .
, JVM, Scala, :
List(3,5,7,11,13,17).exists(_ % 2 == 0)