Lambdaj supports filtering of collections without repetition statements or inner classes as follows::
List<Person> beerDrinkers = select(persons, having(on(Person.class).getAge(),
greaterThan(16)));
Please refer to the following:
https://code.google.com/archive/p/lambdaj/
Update:
With Java 8 (2014) with stream and lambda expression, the above problem can be solved in a single line:
List<Person> beerDrinkers = persons.stream()
.filter(p -> p.getAge() > 16).collect(Collectors.toList());
See also Tutorial .
If you do not want to modify the data in the collection immediately, you can also use Collection#removeIf
:
persons.removeIf(p -> p.getAge() > 16);
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.