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
Since java 9
Collectors.filtering
is enabled:Thus filtering should be:
Example:
I needed to filter a list depending on the values already present in the list. For example, remove all values following that is less than the current value. {2 5 3 4 7 5} -> {2 5 7}. Or for example to remove all duplicates {3 5 4 2 3 5 6} -> {3 5 4 2 6}.
This will bee used like this.
https://code.google.com/p/joquery/
Supports different possibilities,
Given collection,
of type,
Filter
Java 7
Java 8
Also,
Sorting (also available for the Java 7)
Grouping (also available for the Java 7)
Joins (also available for the Java 7)
Given,
Can be Joined like,
Expressions
Consider Google Collections for an updated Collections framework that supports generics.
UPDATE: The google collections library is now deprecated. You should use the latest release of Guava instead. It still has all the same extensions to the collections framework including a mechanism for filtering based on a predicate.
Are you sure you want to filter the Collection itself, rather than an iterator?
see org.apache.commons.collections.iterators.FilterIterator
or using version 4 of apache commons org.apache.commons.collections4.iterators.FilterIterator
Since the early release of Java 8, you could try something like:
For example, if you had a list of integers and you wanted to filter the numbers that are > 10 and then print out those numbers to the console, you could do something like: