concatenation « StringBuilder « Java Data Type Q&A





1. Is there a faster method then StringBuilder for a max 9-10 step string concatenation?    stackoverflow.com

I have this code to concate some array elements:

StringBuilder sb = new StringBuilder();
private RatedMessage joinMessage(int step, boolean isresult) {
        sb.delete(0, sb.length());
    ...

2. If String concatenation using + is implemented using StringBuilder then why are extra objects created during concatenation?    stackoverflow.com

If the following code:

String s = "a" + 1 + "b";// 1.
Is implemented using using StringBuilder equivalent to
String s = new StringBuilder().append("a").append(1).append("b");
then will extra objects "a" and "b" be created in ...

3. Is chain of StringBuilder.append more efficient than string concatenation?    stackoverflow.com

According to Netbeans hint named Use chain of .append methods instead of string concatenation

Looks for string concatenation in the parameter of an invocation of the append method of StringBuilder ...

4. String concatenation in Java - when to use +, StringBuilder and concat    stackoverflow.com

When should we use + for concatenation of strings, when is StringBuilder preferred and When is it suitable to use concat. I've heard StringBuilder is preferable for concatenation within loops. Why is ...

5. String concatenation vs. StringBuilder.    java-forums.org

Indeed the StringBuilder class is FAR faster for VERY LONG Strings. I have created code to time the two below: Java Code: public class StringStuff { public static void main( String[] args ) { StringStuff m = new StringStuff(); m.addStrings(); } public void addStrings() { int i, j; int numberStrings = 100000; long initTime, finalTime; double totalTime; System.out.println( "Using String concatenation" ...