I want to filter a java.util.Collection
based on a predicate.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
With Guava:
The setup:
The usage:
How about some plain and straighforward Java
Simple, readable and easy (and works in Android!) But if you're using Java 8 you can do it in a sweet one line:
Note that toList() is statically imported
The Collections2.filter(Collection,Predicate) method in Google's Guava library does just what you're looking for.
Use Collection Query Engine (CQEngine). It is by far the fastest way to do this.
See also: How do you query object collections in Java (Criteria/SQL-like)?
Some really great great answers here. Me, I'd like to keep thins as simple and readable as possible: