Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Pros:
    • avoids the null pointer exception issue that Solution 1 has
    • readable but awkward at first. Maybe use EMPTY_STRING.equals(someString)
  • Cons:
    • create extra String object (""). Overhead can be reduced by using static final String EMPTY_STRING = "";
    • not very efficient because equals first does a string length comparison

...