🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #7753

Re: Different between String("") and String()

#7753
From: John McGrath TeamB
Date: Tue, 22 May 2001 22:05
25 lines
1589 bytes
On Tue, 22 May 2001 19:45:07 +0100, Mark Griffiths wrote:

> > String x = new String();
> > String y = new String("");
> 
> Yes, both create an empty string.  I took a quick look at
> the source code for java.lang.String, and I think it is fair
> to say that the first form is marginally more efficient.

That is true.  An even more efficient way to do this that is almost 
equivalent is:

    String x = "";

Unless you are doing some strange things, testing for object identity, 
this will work the same as the above code.

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID: <MPG.1574a2e3dc641c2a98a213@forums.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!t-online.de!news1.dtag.de!news.gwi-ag.com!dnews
References: <3b0aacf1_2@dnews> <3b0ab393$1_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,a9ac66d2eb8cf715
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-05-22 15:14:09 PST
From: John McGrath  [TeamB] <ng-b@JPMcGrath.net>
Newsgroups: borland.public.jbuilder.java.language
Subject: Re: Different between String("") and String()
Date: Tue, 22 May 2001 18:05:41 -0400
Message-ID: <MPG.1574a2e3dc641c2a98a213@forums.borland.com>
References: <3b0aacf1_2@dnews> <3b0ab393$1_1@dnews>
X-Newsreader: MicroPlanet Gravity v2.30
NNTP-Posting-Host: 209.92.40.60
X-Trace: dnews 990569140 209.92.40.60 (22 May 2001 15:05:40 -0700)
Lines: 25
X-Authenticated-User: jpmcgrath
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!t-online.de!news1.dtag.de!news.gwi-ag.com!dnews