AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Java programming style question

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Software Tools
View previous topic :: View next topic  
Author Message
David Kerber
Guest





PostPosted: Fri May 04, 2007 7:00 pm    Post subject: Java programming style question Reply with quote



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( "" )?

TIA!
Dave
--
Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).
Back to top
Daniel Dyer
Guest





PostPosted: Fri May 04, 2007 7:20 pm    Post subject: Re: Java programming style question Reply with quote



On Fri, 04 May 2007 15:00:35 +0100, David Kerber
<ns_dkerber (AT) ns_WarrenRogersAssociates (DOT) com> wrote:

Quote:
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.

--
Daniel Dyer
http://www.uncommons.org
Back to top
David Kerber
Guest





PostPosted: Fri May 04, 2007 7:39 pm    Post subject: Re: Java programming style question Reply with quote



In article <op.trs3fvbv8kxvgr (AT) cgl0656 (DOT) chaucer.co.uk>, "Daniel Dyer"
<"You don't need it"> says...
Quote:
On Fri, 04 May 2007 15:00:35 +0100, David Kerber
ns_dkerber (AT) ns_WarrenRogersAssociates (DOT) com> wrote:

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

Yeah, I already learned that lesson :-D

Quote:
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!

.....

--
Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).
Back to top
Mike
Guest





PostPosted: Fri May 04, 2007 9:00 pm    Post subject: Re: Java programming style question Reply with quote

On May 4, 3:00 pm, David Kerber
<ns_dkerber (AT) ns_WarrenRogersAssociates (DOT) com> wrote:
Quote:
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( "" )?

TIA!
Dave
--
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.
Back to top
David Kerber
Guest





PostPosted: Sat May 05, 2007 7:08 am    Post subject: Re: Java programming style question Reply with quote

In article <1178294413.418046.7710 (AT) n76g2000hsh (DOT) googlegroups.com>,
mike.mkaufman (AT) googlemail (DOT) com says...
Quote:
On May 4, 3:00 pm, David Kerber
ns_dkerber (AT) ns_WarrenRogersAssociates (DOT) com> wrote:
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( "" )?

TIA!
Dave
--
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.

Yes, I'm using 1.5, so that's what I'll use. Thanks for the comments,
guys!

--
Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Software Tools All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.