Good day all, I am new to Java, and have a simple question that I could not find a definitive answer for anywhere.
I'm trying to use a conditional statement based on the contents of a string variable. I have a variable which contains a string I've gleaned from a SQL database. I want to check and see what this string is, then manipulate some form objects accordingly. See code snippet below:
if (gender == "Male") {
Gender.setSelectedIndex(0);
} else if (gender == "Female") {
Gender.setSelectedIndex(1);
} else {
Gender.setSelectedIndex(2); }
No matter what the string is, I get setSelectedIndex(2) which leads me to believe theres a problem comparing the strings to each other in this type of statement.
Can somebody shed some light? :)