I have a list which is defined as below:
def list1=["Test1","Test2","Test3"]
String str="Test2"
println("Found The String is:"+list1.contains(str));
//It is returning false even though there is a matching string.
I have a list which is defined as below:
def list1=["Test1","Test2","Test3"]
String str="Test2"
println("Found The String is:"+list1.contains(str));
//It is returning false even though there is a matching string.
What you've typed in there does work, so there's something else wrong. My guess is that you've done something like:
String part = "Test"
String str="Test2"
def list1=["${part}1","${part}2","Test3"]
def found = list1.contains(str)
in this case, found
will be false... because:
"${'test'}"
is not equal to "test"
, for some definitions of equal... even though printing them both makes you think so.
Here's why: Groovy different results on using equals() and == on a GStringImpl