Pages

Saturday, December 8, 2012

what is the difference between String Builder and string?

String Builder is useful when need to build strings in multiple steps.

EX:

String:

 String x="";
 x +="michael";
 x +="jackson";

String Builder:

 StringBuilder sbObj=new StringBuilder("");
 sbObj.Append("michael");
 sbObj.Append("jackson");
 String x=sbObj.Tistring();

Both will give the same results but StringBuilder will take less memory and runs faster.String each time it will create new instance where as StringBuilder will create chunks and add only add at the end it will unite it.

0 comments:

Post a Comment