I have
String x = g.substring(0, 1);
if (x == "S") {
stuff
}
I have a string, “Safety”, but “stuff” doesn’t run and my watch say x value = S and x=="S" = false.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
==is used foridentitycomparison, and it checks whether the tworeferencepoints to the same object (in your case the object isString).You should use the
equalsmethod to compare the contents of your string: