You can use lambdaj . Such things are trivial, the syntax is really smooth:
Person me = new Person("Mario", "Fusco", 35); Person luca = new Person("Luca", "Marrocco", 29); Person biagio = new Person("Biagio", "Beatrice", 39); Person celestino = new Person("Celestino", "Bellone", 29); List<Person> meAndMyFriends = asList(me, luca, biagio, celestino); List<Person> oldFriends = filter(having(on(Person.class).getAge(), greaterThan(30)), meAndMyFriends);
and you can do much more complex things. It uses hamcrest for matches. Some argue that this is not a Java style, but it's funny how this guy twisted Java to do a bit of functional programming. Look also at the source code, which is pretty sci-fi.
Gismo Ranas Dec 06 '13 at 11:12 2013-12-06 11:12
source share