Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xilin/e8beada46face1b4b75c to your computer and use it in GitHub Desktop.
Save xilin/e8beada46face1b4b75c to your computer and use it in GitHub Desktop.
import static java.lang.System.out;
import static java.util.Arrays.asList;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
public class ListTests {
public static void main( String[] args ) {
List<String> names = asList( "Ted", "Fred", "Jed", "Ned" );
out.println( names );
List<String> shortNames = new ArrayList<String>();
shortNames.addAll( names );
CollectionUtils.filter( shortNames, new Predicate(){
public boolean evaluate( Object input ) {
return ((String) input).length() < 4;
}
} );
out.println( shortNames.size() );
for( String s : shortNames )
out.println( s );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment