Created
February 18, 2013 15:49
-
-
Save aeg/4978345 to your computer and use it in GitHub Desktop.
指定した条件を満たす要素をリストから削除する。
This file contains hidden or 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
// Case #1 | |
// 指定した条件を満たす要素を削除したリストを作成する | |
def list1 = [1, 3, 7, 10, 13] | |
assert list1.findAll{!(it < 10)} == [10, 13] | |
// Case #2 | |
// 指定した条件を満たす要素をリストから削除する | |
list1.removeAll {it < 10} | |
assert list1 == [10, 13] | |
// Case #3 | |
// 指定した条件を満たす要素をリストから削除する | |
list1 = [1, 3, 7, 10, 13] | |
list1.retainAll(list1.findAll {!(it < 10)}) | |
assert list1 == [10, 13] | |
// Case #4 | |
// 指定した条件を満たす要素をリストから削除する | |
list1 = [1, 3, 7, 10, 13] | |
list1.removeAll([1, 3, 7]) | |
assert list1 == [10, 13] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment