I'm having some trouble figuring out how to accomplish what I am looking for. Let's say I have 5 different String variables: String string1 = "A"
String string2 = "B"
String string3 = "A"
String string4 = "B"
String string5 = "A"
What I want to do is loop over those 5 variables and if they equal B, I want to set them to A. What I have tried is something like:
[string1,string2,string3,string4,string5].each {
if (it == "B"){
//don't know what to put here
need to set variable = "A" here
}
}
I don't know how to get the actual variable name in the closure for the assignment. Maybe I am not searching correctly for what I am trying to do, but I need to be able to set strin2 and string4 to "A" with this loop.
I know I can do 5 if statements, but I know there has got to be a better way.
string1point to, or do you want to leave that reference as it is and just put a new value in the List in place of the old one (which would not have any impact on thestring1reference)?obj['string1'] = "B"will do the assignment. if they are the local variables - then no chance.