什么是Groovy模拟后续操作?
list.stream().anyMatch(b -> b == 0);
You mean to find if the list contains element 0
?
def list = [0,1,2,3,4]
def result = list.any{it == 0}
println result
You can quickly try it online demo
Groovy syntax has a spectrum that ranges from Java-esque to idiomatic Groovy. Both of these work:
// Java-esque
List<Integer> list = [4,3,2,1,0]
assert list.stream().any{ b -> b == 0 }
// Groovier (note `it` is an alias for the parameter)
def list2 = [4,3,2,1,0]
assert list2.stream().any{ it == 0 }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.