Rob Prime wrote:I don't see why this method was added anyway. It's just shorthand for length() == 0. The only advantage is 4 characters less.
Only four characters, but for me it's more about having less cognitive overhead. This seems like a big readability ROI:
Less syntactic noise and more expressive; I find
isEmpty to be much clearer, and tells a better story when read out loud (my ultimate standard of readability). There's a reason every
string utility package has
isEmpty() and/or
isBlank()...
And both ELs and non-Java JVM languages can call it with
foo.empty which is cleaner still--without having to monkeypatch String.