Skip to content

Instantly share code, notes, and snippets.

@djangofan
Forked from quicy/CollectionFilter.xtend
Created August 7, 2012 19:49
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 djangofan/3288775 to your computer and use it in GitHub Desktop.
Save djangofan/3288775 to your computer and use it in GitHub Desktop.
Collection filter by Xtend closure
import java.util.List
import static extension java.util.Collections.*
class CollectionFilter {
def static void main(String[] _) {
val values = new ArrayList( 1, 5, 33, 0, -2, -10, 4, 36, -82 )
positiveOnly( values )
negativeOnly( values )
}
def static positiveOnly( List<Integer> values ) {
values.filter( v| v >= 0 )
println( values )
}
def static negativeOnly( List<Integer> values ) {
values.filter( v| v < 0)
println( values )
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment