UPDATE: Thank you all for your answers, especially pertaining to .equals().
The only detail is that the "msgCode = ..." and "msgValue = ..." statements are enough to return an empty stirngBuilder. I.e., I don't even have to declare the IF statement to make it stop working.
Any clues?
ORIGINAL:
Please let me know why StringBuilder
returns nothing (perhaps doesn't even work) when I include the rest of the code (besides stringBuilder.append(...)
) inside the while()
.
When I include just stringBuilder.append(...)
, then there is a return value.
while ( (receiveString = bufferedReader.readLine()) != null ) {
stringBuilder.append(receiveString + "\n");
// analyze the first 3 characters in the message
String msgCode = receiveString.substring(0, 3);
Number msgValue = Integer.parseInt(receiveString.substring(4, receiveString.length()-4));
// use IF-ELSE since SWITCH doesn't work with String
if (msgCode=="ATT") {
dataATT[2*dataATTcount+1] = msgValue;
dataATTcount++;
} else {
dataMED[2*dataMEDcount+1] = msgValue;
dataMEDcount++;
}
}
Thanks