Generally, when a new programmer wants to check to see if the values of 2 strings are the same, the first thing he/she tries is this:
if (someString == "Yes") {
....
}
But that\'s wrong. Java is just checking the equality refrences at this point (remember- a java String is an object made up of chars and other goodies), and that\'s not what we want to do. We want to do is check the _values_ that are stored in the String(s).
So that\'s why we have the String.equals(String) method. Try this out:
if (someString.equals("Yes")) {
....
}
Ah- much better. But there is still one more problem. What if for some reason someString is null? Well, we would get a null pointer exception thrown, and probably see a stack trace show up somewhere. A much safer way would be to do it like this:
if ("Yes".equals(someString)) {
....
}
And this way, we will never get a null pointer exception.