Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Strings in If conditional statements

807598Jul 18 2006 — edited Aug 10 2006
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? :)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 7 2006
Added on Jul 18 2006
4 comments
387 views