The Apache Commons method StringUtils.isNotBlank will return false if the string is null, empty, or contains only whitespace. There will be differences in the following situations:
| str1 | str2 | Results(1st code/2nd code) |
|---|---|---|
| null | null | false/true |
| "" | "" | false/true |
| " " | " " | false/true |
Both the methods in the Java String class and the methods in StringUtils are highly optimised for the specific tasks they were designed to solve. Different methods are designed to solve slightly different tasks. Try to pick the method that most closely matches the task you are trying to solve, and it's likely you will get very good performance.
If there are two possible approaches that look equally good, and it's vital to get every last bit of performance, then measure it! Time the performance of both approaches on your actual data.
But also remember that it's often cheaper to buy a faster computer instead of spending hours of development time micro-optimizing your code to get it to run fast on a slow machine.
Well it probably depends on each individual method. Most of the methods represent very basic code that people often have to write by hand such as
return s1 == s2 || (s1 == null && s2 == null) || (s1 != null && s1.equals( s2 ) );
This code would very likely be optimised to the same thing by the hotspot compiler removing even the method call. I would guess that the only savings in time you'll find are in writing.
As suggested elsewhere, I would just recommend benchmarking the methods you are interesting in yourself use System.currentTimeMillis() around a loop that calls the method on some random strings; random because you don't want it optimised away.