GeeCON Prague 2014*
The moose likes Java in General and the fly likes  Conversion String concordinate  (using +) to StingBuffer Class are no longer needed in Java 1.5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark " Conversion String concordinate  (using +) to StingBuffer Class are no longer needed in Java 1.5" Watch " Conversion String concordinate  (using +) to StingBuffer Class are no longer needed in Java 1.5" New topic
Author

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

Mohammed Yousuff
Ranch Hand

Joined: Oct 17, 2007
Posts: 198
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.


My Thoughts : http://passion4java.blogspot.com
Try not to become a man of success but rather to become a man of value.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Hi Mohammed,
Please CarefullyChooseOneForum next time. I'm moving your thread out of "Jobs Discussion".


[My Blog]
All roads lead to JavaRanch
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42030
    
  64
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?


Ping & DNS - my free Android networking tools app
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14193
    
  20

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Conversion String concordinate (using +) to StingBuffer Class are no longer needed in Java 1.5