In Groovy, I am taking the values from a Map and creating a List from this. I then want to check if that List (of values) is empty.
My whole aim is to check if ALL the values of myMap
are blank or empty.
In the code below, the values of myMap
will either be an empty string or have some value.
Map myMap = [:]
myMap["a"] = "$A"
myMap["b"] = "$B"
myMap["c"] = "$C"
List myList = myMap.values() //[, , , ]
myList
returns [, , , ]
. How do I check this List contains all empty strings or do I go about this a whole other way?
Thanks
Use every
myList.every { it == '' }
To check if any of them are ''
, use any
myList.any { it == '' }
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