
Signature
Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).
> What is the preferred way of checking for an empty string that I already
> know is not Null?
>
> Is it better (however you define that) to check for .length = 0, or
> .equals( "" )?
I don't think it really matters, as long as you don't use ==. IntelliJ
IDEA suggests using .length() for performance reasons, but I doubt it
would make any noticeable difference in most cases.
Dan.

Signature
Daniel Dyer
http://www.uncommons.org
David Kerber - 04 May 2007 15:39 GMT
> > What is the preferred way of checking for an empty string that I already
> > know is not Null?
[quoted text clipped - 3 lines]
>
> I don't think it really matters, as long as you don't use ==. IntelliJ
Yeah, I already learned that lesson :-D
> IDEA suggests using .length() for performance reasons, but I doubt it
> would make any noticeable difference in most cases.
That's kind of what I figured; thanks!
....

Signature
Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).
On May 4, 3:00 pm, David Kerber
<ns_dkerber@ns_WarrenRogersAssociates.com> wrote:
> What is the preferred way of checking for an empty string that I already
> know is not Null?
[quoted text clipped - 7 lines]
> Remove the ns_ from if replying by e-mail (but keep posts in the
> newsgroups if possible).
As of JDK 6, the String class now has an "isEmpty" method that returns
true if the length is zero. So I'd say use "isEmpty" if on JDK 6, or
otherwise check the length.
David Kerber - 05 May 2007 03:08 GMT
> On May 4, 3:00 pm, David Kerber
> <ns_dkerber@ns_WarrenRogersAssociates.com> wrote:
[quoted text clipped - 13 lines]
> true if the length is zero. So I'd say use "isEmpty" if on JDK 6, or
> otherwise check the length.
Yes, I'm using 1.5, so that's what I'll use. Thanks for the comments,
guys!

Signature
Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).