Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save karstengresch/5e1639c137e42dfef087 to your computer and use it in GitHub Desktop.
Save karstengresch/5e1639c137e42dfef087 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