它在接收對象中找到與關閉條件匹配的所有值。
用法
List findAll(Closure closure)
參數
集合元素要滿足的條件在必須是某個布爾表達式的閉包中指定。
返回值
find 方法返回根據表達式找到的所有值的列表。
示例
以下是此方法的使用示例~
class Example {
static void main(String[] args) {
def lst = [1,2,3,4];
def value;
value = lst.findAll{element -> element > 2}
value.each {println it}
}
}
當我們運行上麵的程序時,我們會得到以下結果——
3 4
相關用法
- Groovy find()用法及代碼示例
- Groovy floor()用法及代碼示例
- Groovy matches()用法及代碼示例
- Groovy after()用法及代碼示例
- Groovy padRight()用法及代碼示例
- Groovy contains()用法及代碼示例
- Groovy exp()用法及代碼示例
- Groovy equals()用法及代碼示例
- Groovy before()用法及代碼示例
- Groovy pow()用法及代碼示例
- Groovy sin()用法及代碼示例
- Groovy concat()用法及代碼示例
- Groovy random()用法及代碼示例
- Groovy endsWith()用法及代碼示例
注:本文由純淨天空篩選整理自 Groovy - findAll()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。