Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why StringBuilder was removed?

My question is simple. Some time ago StringBuilder was removed. What may be the reason of that? How can I deal with large strings now?

like image 254
Eugeny89 Avatar asked Sep 12 '11 12:09

Eugeny89


People also ask

When should you not use StringBuilder?

If you are using two or three string concatenations, use a string. StringBuilder will improve performance in cases where you make repeated modifications to a string or concatenate many strings together. In short, use StringBuilder only for a large number of concatenations.

Why is StringBuilder not thread-safe?

Because StringBuilder is not a synchronized one whereas StringBuffer is a synchronized one. When using StringBuilder in a multithreaded environment multiple threads can acess the StringBuilder object simultaneously and the output it produces can't be predicted hence StringBuilder is not a thread safe...

Why did you use StringBuilder instead of String?

StringBuilder is used to represent a mutable string of characters. Mutable means the string which can be changed. So String objects are immutable but StringBuilder is the mutable string type. It will not create a new modified instance of the current string object but do the modifications in the existing string object.

What can I use instead of StringBuilder?

StringBuilder is used when we want to modify Java strings in-place. StringBuffer is a thread-safe equivalent similar of StringBuilder . StringBuilder has methods such as append , insert , or replace that allow to modify strings.


3 Answers

flash.utils.StringBuilder was first introduced as a response to a lack of performance in String concatanation. But then String concatanation was optimized so there were no reason to use/keep this Class.

Quote from http://onflex.org/ACDS/AS3TuningInsideAVM2JIT.pdf page 38

For awhile, we had a class flash.utils.StringBuilder for fast string concatenation What happened? A: We made the + operator super-fast by implementing compound strings (cords), so StringBuilder was unneeded and removed

like image 137
Patrick Avatar answered Oct 01 '22 09:10

Patrick


I don't know for StringBuilder, for if you are using Flex there's the (open source) StringUtil Class. I guess you could use the it as is by copying the source file in your project. I know downloading the whole SDK for one file can be a turn off, but I don't think I can link directly to the file.

You can also check out this related question : StringBuilder in Flex

like image 29
Exort Avatar answered Oct 01 '22 08:10

Exort


StringBuilder class was present in early Flash Player 8.5/9 Alphas and Betas, so I don't think they even finished it.

If you are worried about Visible text, you can use TextField.appendText method, which supposed to be optimised String modification method.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html#appendText()

like image 43
David Sergey Avatar answered Oct 01 '22 08:10

David Sergey