使用Google Guava的过滤器.
Collections2.filter(yourOriginalCollection, new Predicate<Object>() {
public boolean apply(Object obj) {
return obj instanceof TypeYouAreInterestedIn;
}
});
Run Code Online (Sandbox Code Playgroud)
或者在Java 8中:
Collections2.filter(yourOriginalCollection, (obj) -> obj instanceof TypeYouAreInterestedIn);
Run Code Online (Sandbox Code Playgroud)