Source link: http://stackoverflow.com/questions/587404/java-finding-objects-in-collections/588452#588452
Sample code is:
public static void main(String[] args) {
Collection<String> bigList = new ArrayList<String>();
bigList.add( "Nick" );
bigList.add( "Bay" );
bigList.add( "Lei" );
bigList.add( "Jonna" );
System. out.println(bigList);
Collection<String> smallList = CollectionUtils . select (bigList, new Predicate(){
public boolean evaluate(Object o) {
String attribute = (String)o;
return attribute.equals( "Jonna" ) || attribute.equals( "Bay" ) ;
}
}) ;
System. out .println(smallList);
}
output:
[Jonna, Bay]