4 ms·
This can be a lot shorter using Google Guava [1]: Collections2.filter( Lists.newArrayList(1, 2, 3, 4), new Predicate<In
by julian37 16y ago
This can be a lot shorter using Google Guava [1]:
Collections2.filter(
Lists.newArrayList(1, 2, 3, 4),
new Predicate<Integer>() {
public boolean apply(Integer i) {
return i % 2 == 0;
}
});
As I understand it, JDK 8 will support lambdas which will make it shorter still.
[1] http://code.google.com/p/guava-libraries/ http://code.google.com/p/guava-libraries/
- democracy 16y agoOr apache collections: CollectionUtils.filter(new ArrayList(Arrays.asList(1, 2, 3, 4)), new Predicate() { public boolean evaluate(Object v) { return ((Integer) v).intValue() % 2 == 0; } });
- shikyo 16y agoOr with http://code.google.com/p/totallylazy/ http://code.google.com/p/totallylazy/ (ignoring imports): sequence(1,2,3,4).filter(even());