| Author |
String and StringBuffer
|
Nimish Patel
Ranch Hand
Joined: Jun 29, 2005
Posts: 84
|
|
hi all, we can concate string using string class and stringbuffer class. but what is better from both ? suppose when long string concate process , which one better , string or string buffer ? please advise me. Thanks, Nimish Patel
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24045
|
|
|
I'm going to move this to "Java in General (Beginner)" and then answer it.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24045
|
|
String catenation is implemented using StringBuffer. So, for example, String s3 = s1 + s2; will be compiled into something like StringBuffer _tmp = new StringBuffer(s1); _tmp.append(s2); String s3 = _tmp.toString(); So really, they're the same. But if you're adding multiple Strings together, and you're doing it in a loop where performance matters, then you can generally write more efficient StringBuffer code by hand than the compiler will generate.
|
 |
 |
|
|
subject: String and StringBuffer
|
|
|