O'Reilly logo

Just Java™ 2 by Peter van der Linden

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

String Comparison

image

Just a reminder about String comparisons. Compare two Strings like this:

if ( s1.equals(s2) )

not like this:

if (s1 == s2)

The first compares string contents, the second, string addresses (this is another artifact of reference types, remember?). Failing to use equals() to compare two strings is probably the most common single mistake made by Java novices.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required