I'm having trouble getting a variable that is modified during a for loop to retain the new value after exiting the loop.
So I have an array called 'outputP' that stores String values. Then I have a for loop with a nested if statement that checks to see if another String value matches one of the strings in outputP and then sets a value for the int variable 'visitCode.':
String[] outputP = { "SC", "BL", "V04", "V06" };
int index = folder.getName().indexOf("_R");
String[] split = folder.getName().substring(index +1).split("_");
subjectInfo = new String[]{folder.getName().substring(0,index), split[0], split[1]};
if (subjectInfo[0].charAt(0) != 'S'
|| subjectInfo[1].charAt(0) != 'R'
|| Arrays.asList(outputP).contains(subjectInfo[2] != true ){
//Code here outputs error message
}
int groupCode;
int visitCode = 0;
groupCode = Integer.parseInt(subjectInfo[1].substring(1));
for (int i = 0; i < outputP.length; i++)
{
if (subjectInfo[2] == outputP[i])
{
visitCode = i + 1;
}
}
During debugging I've verified during one run that outputP[0] and subjectInfo[2] are both "SC", when I step through the code, it skips over the if statement and visitCode is left equaling 0. I also included above that first if statement, because, it functions as you would expect it to, recognizing that subjectInfo[2] (which was set to "SC") is a string that is also in the outputP array. Does anyone see something that I'm missing that would cause the compiler to skip over the nested if statement?
Thanks in advance to anyone who can help.