Given
String myString = "blah"
List list = ["a", "b", "cblah", "dblah"]
Task
Check if "blah" is contained in any element of list
.
Solution
println list.any { it.contains(myString) }
println list.find { it.contains(myString) }
list.findAll { it.contains(myString) }.each { print it + " " }
Console output
true
cblah
cblah dblah
Explanation
any
returns true or false.
find
returns the first element that contains "blah".
findAll
returns all elements that contain "blah".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With