Java String Equals

by Dan Bunker

 

String Equals

When you need to compare two string together to see if they are equal or not, the Java String class provides a couple of methods that you will want to know. String equality can be case-sensitive or case-insensitive depending on your needs. The equals method is case sensitive and all characters in the string have to match in the same sequence. The equalsIgnoreCase method is case insensitive. Only these two methods should be used for string equality. Don't use the double equals (==) for string comparison since that will check object references for equality rather than character equality.