Answer to Question #49979 in Engineering for Paul

Question #49979
In java how can we use the concept of stringbuilder
1
Expert's answer
2014-12-15T00:50:38-0500
If you use Stringconcatenation in a loop (something like:
String s ="";
for(int i = 0; i <100; i++) {
s += ", " + i;
}
then you should usea StringBuilder (not StringBuffer)instead of a String, because it is much faster and consumes less memory.
If you have a singlestatement:
String s = "1," + "2, " + "3, " + "4, " ....;
then you can useStrings, because the compiler will use StringBuilder automatically.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS