Why is it recommended to use concat method instead of + operator? Please explain the difference. I'm a beginner. regards, sam.
Joined: Jan 29, 2003
Curious. I'd never loooked at concat before. About the only thing that looks different is when the string you are adding has zero length it just gives you back the original instead of creating a new String. The + operator can be a bit expensive ... if you are doing hundreds or thousands of string building operations look into StringBuffer.append(). It is common to see a method build up a StringBuffer and then return or use theBuffer.toString() at the end.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Pradeep Bhat: Where did you get the statement ? StringBuffers are recomended over String for concatination operations.
And even that's an oversimplification. StringBuffers are actually rather rarely needed to be used explicitely.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus