Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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/



Or with http://code.google.com/p/totallylazy/ (ignoring imports):

sequence(1,2,3,4).filter(even());


Or 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;
			}
		});




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: