-
-
Save djangofan/3288775 to your computer and use it in GitHub Desktop.
Collection filter by Xtend closure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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