I didn't read in full everything here, but using StringBuilder is good old 
optimization, strange many don't know it here...
http://www.venishjoe.net/2009/11/java-string-concatenation-and.html
Having said that it seems that both of you are kind of right, recent JDK's 
compile '+' into StringBuilder, but not in all cases, so you have to be 
carefull. 
For example, this would be compiled into builder: 
String ab = a + b;
but this will be compiled into 2 StringBuilder... 
String ab = "ab";
ab += a;
ab += b;

вторник, 24 июля 2012 г., 20:40:10 UTC+3 пользователь Brandon Wirtz написал:
>
> And you get a new string builder each loop. If you use string builder and 
> recycle it you don't have to re-create the object. Which doesn't create so 
> much garbage. 
> You have the answer and you don't understand it. 
>
>
>
> > Try compiling these two classes.  They produce *identical* class files: 
> > 
> > ---- File m1/Stringy.java ---- 
> > public class Stringy { 
> >         public static void main(String[] args) { 
> >                 String foo = "def"; 
> >                 System.out.println("abc" + foo); 
> >         } 
> > } 
> > ---- File m2/Stringy.java ---- 
> > public class Stringy { 
> >         public static void main(String[] args) { 
> >                 String foo = "def"; 
> >                 System.out.println(new 
> > StringBuilder().append("abc").append(foo).toString()); 
> >         } 
> > } 
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/CDZcdLF0bIgJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to