If I got a list in Groovy containing 2 or more variables with some value, and I want to see if it contains the given text string, I do the following:
def msg = ''' Hello Mars! ''' def msg1 = ''' Hello world! ''' def list = [msg, msg1] list.findAll { w -> if(w.contains("Hello")) { println w } else { println "Not there" } }
But instead of printing the value, I would like to print the name of the variable containing the text. Is this possible with a list or do I need to make a map?
source share