Re: Newbie String Questions
- From: "Steve W. Jackson" <stevewjackson@xxxxxxxxxxx>
- Date: Tue, 28 Nov 2006 16:40:29 -0600
In article <456cb38d$0$8759$ed2619ec@xxxxxxxxxxxxxxxxxxxxxxxxxx>,
Wesley Hall <noreply@xxxxxxxxxxx> wrote:
Dom wrote:
[ snip ]
2. Why is there a concat method? Is there any difference between
these statements:
a) -- s = s.concat ("ABC");
b) -- s = s + "ABC";
Functionally, there is no difference, although there are probably some
subtle things related to the above. I can't be bothered to think it
through right now :oP
I agree that there's no functional difference, but it may be better to
use the concat method rather than the + operator.
The Javadocs for String indicate that the language has special support
for the concatenation operator (+) and indicates how it works. In the
source, you find that concat does a check for a zero-length parameter,
resulting in returning the original reference and thus no change to the
heap. But if a non-empty parameter is passed, it builds an array of
char to hold the old and new strings, then returns the result of calling
a String constructor with that array. Which is actually better probably
depends on a lot of factors, so...let's just say that the sure fire best
thing is not to do either in large quantities, preferring instead to use
a StringBuilder or StringBuffer.
= Steve =
--
Steve W. Jackson
Montgomery, Alabama
.
- References:
- Newbie String Questions
- From: Dom
- Re: Newbie String Questions
- From: Wesley Hall
- Newbie String Questions
- Prev by Date: JAVA Time Problem: Want to get the current time and perform validation
- Next by Date: Re: JAVA Time Problem: Want to get the current time and perform validation
- Previous by thread: Re: Newbie String Questions
- Next by thread: JAVA Time Problem: Want to get the current time and perform validation
- Index(es):
Relevant Pages
|