Compare two String using StringUtils from Apache Commons

The StringUtils class of the Apache Commons Lang library supplies a method for comparing String without checking them for null values first.
Normally when comparing with standard Java methods of the String class you need to check them for null first to avoid any NullPointerException being thrown, like:

However, with the StringUtils class you don’t need to do any null checks since it takes care of that part for you. The only thing you need to provide are the two strings to compare:

The output from the code above is:

Search for more Java info on this site here:
Custom Search

Please type any questions here.