Ye Olde == vs. Equals, with Strings

In this tip you saw that the only safe way to test that Strings have the same value is with the equals() method. If you work with Strings that have the same value, then it might be worth interning them into the constants pool. That way you can make a quicker check using the == operator. In any case, you can see that you have to be careful before deciding to use == to check equivalence.

This months Sun’s Java-spam (or whatever it’s called) has an article on == and .equals for String. Here’s a tip: if you’re going to be interviewing for a job, read this and understand it.