Jakarta Commons

Say you have a Person class and a collection of Person objects. You want to find the first occurence of a Person whose first name is Mike.

First approach:

Person person = null;

for (Person item : persons)
if (item.name.equals("Mike"))
person = item;

Second approach using apache commons libraries (isn't this more elegant?)

Person person
= CollectionsUtils.find(persons, new BeanPredicate("name", new EqualPredicate("Mike")));