I have a list of string elements named options.
I am trying to do following:
for (String i: options){
if (i != "1" && i != "2" && i != "3" && i != "4")
{
break;
}
}
Is it possible to do something like if (i not in ['1', '2', '3', '4']){break;}
I have a list of string elements named options.
I am trying to do following:
for (String i: options){
if (i != "1" && i != "2" && i != "3" && i != "4")
{
break;
}
}
Is it possible to do something like if (i not in ['1', '2', '3', '4']){break;}
You should use Set.
Set base = ["1", "2", "3", "4"] as Set
Set data = ["5"] as Set
Set rest = data.minus(base)
assert rest.size() == 0 : "one or more elements of the data(" + data + ") is not contained in the base ("+ base +")"
my base set is [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5]
and my data set is [2, 2.5, 3, 3.5]
But I am still getting the following error:
java.lang.AssertionError: one or more elements of the data([[2, 2.5, 3, 3.5]]) is not contained in the base ([0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5]). Expression: (rest.size() == 0)
Is this error correct? because 2, 2.5, 3 and 3.5 is in the base set, no?
Update: Ah, nvm. It was my mistake, I was using Set data = ["5"] as Set
as Set data = [myListname] as Set