tag:blogger.com,1999:blog-8563220776994779598.post5961479349563647605..comments2024-03-17T08:20:24.832-07:00Comments on My Tech Learnings: String Buffer vs StringBuilder vs Concatination Operator +Lavnishhttp://www.blogger.com/profile/16714741724993845980noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-8563220776994779598.post-12492795962189325972008-06-16T23:08:00.000-07:002008-06-16T23:08:00.000-07:00One more news for you. You can now use the nanosec...One more news for you. You can now use the nanosecond functionality of JDK, so you need not to write 10000 loops :)Vaibhav Choudharyhttps://www.blogger.com/profile/11145353943937580111noreply@blogger.comtag:blogger.com,1999:blog-8563220776994779598.post-73960458381447370132008-06-16T23:07:00.000-07:002008-06-16T23:07:00.000-07:00yes, its correct ! StringBuilder is thread-unsafe ...yes, its correct ! StringBuilder is thread-unsafe and fast very similar difference like when you compare ArrayList and Vector. <BR/><BR/>I have checked that somewhere in March,2007 : <BR/><BR/>http://java4ever.blogspot.com/2007/03/string-vs-stringbuffer-vs-stringbuilder.htmlVaibhav Choudharyhttps://www.blogger.com/profile/11145353943937580111noreply@blogger.comtag:blogger.com,1999:blog-8563220776994779598.post-32770334282727713352008-06-11T00:43:00.000-07:002008-06-11T00:43:00.000-07:00thanks for the correction bro ... I changed the co...thanks for the correction bro ... <BR/>I changed the code to <BR/>String str = "one;two";<BR/>str += "three;four;five";<BR/>str += "six;seven";<BR/><BR/>and now the output is <BR/>+ 10360<BR/>StringBuilder 6171<BR/>String Buffer 11907<BR/><BR/>Looks like StringBuilder is clear winner ... and as far as choice between + operator and StringBuffer is considered obviously StringBuffer should be preferred.<BR/><BR/>wat say ??Lavnishhttps://www.blogger.com/profile/16714741724993845980noreply@blogger.comtag:blogger.com,1999:blog-8563220776994779598.post-74523112137877457072008-06-10T12:04:00.000-07:002008-06-10T12:04:00.000-07:00Bro you got this thing a bit wrong. Change the Str...Bro you got this thing a bit wrong. Change the String str = "one;two" + "three;four;" etc to <BR/><BR/>String str = "one;two";<BR/>str += "three;four;five";<BR/>str += "six;seven";<BR/><BR/>Then run your code and see for yourself whats better.<BR/><BR/>Internally String class makes use of the StringBuilder object. So there's no way String can be better than StringBuilder or for that matter even StringBuffer.Anonymousnoreply@blogger.com