Why is this an issue?

Calling String.isEmpty() clearly communicates the code’s intention, which is to test if the string is empty. Using String.length() == 0 is less direct and makes the code less readable. This preference for isEmpty() extends to all CharSequence objects, including StringBuilder and StringBuffer.

How to fix it

Code examples

Noncompliant code example

if ("string".length() == 0) { /* … */ } // Noncompliant

if ("string".length() > 0) { /* … */ } // Noncompliant
StringBuilder sb = new StringBuilder();
...
if (sb.length() == 0) { /* … */ } // Noncompliant

Compliant solution

if ("string".isEmpty()){ /* … */ }

if (!"string".isEmpty()){ /* … */ }
StringBuilder sb = new StringBuilder();
...
if (sb.isEmpty()) { /* … */ }

Resources

Documentation