I am writing an application in Java using Swing. I am trying to convert the value in the text field txtDay
to uppercase before evaluating the value in the below switch statement.
txtDay.getText().toUpperCase();
switch(txtDay.getText()){
case "SUNDAY":
//do something
break;
case "MONDAY":
//do something
break;
case "TUESDAY":
//do something
break;
case "WEDNESDAY":
//do something
break;
case "THURSDAY":
//do something
break;
case "FRIDAY":
//do something
break;
case "SATURDAY":
//do something
break;
default:
//do something
break;
}
Though at the first line (txtDay.getText().toUpperCase()
), I am receiving an error saying "Should check the method return value".
What does this mean? Any tips on how to resolve this?
It's not an error but a warning. It says that you are not using the result of the operation. Strings being immutable, you need something like:
txtDay.setText(txtDay.getText().toUpperCase());
to get the result you expect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With