Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Conversion String concordinate (using +) to StingBuffer Class are no longer needed in Java 1.5

 
Mohammed Yousuff
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Conversion String concordinate (using +) to StingBuffer Class are no longer needed in Java 1.5?. One of my friend is saying this to me.. I tried a simple example and i can still see the performance difference... is this statement is true.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mohammed,
Please CarefullyChooseOneForum next time. I'm moving your thread out of "Jobs Discussion".
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm confused because "+" is generally used in conjunction with String, not StringBuffer. Can you give an example piece of code of the technique you're talking about?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know exactly what you mean with your question, but code that concatenates strings with + is still converted to operations with StringBuilder by the Java compiler in Java 5. Note that it's no longer using StringBuffer, but StringBuilder.

StringBuilder is almost the same as StringBuffer, except that it's not synchronized (similar to the difference between ArrayList and Vector). StringBuffer is a legacy class that should not be used anymore in favour of StringBuilder.

Maybe your friend read something about StringBuffer being obsolete since Java 5 and got confused with this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic