Why to use StringBuffer in Dart instead of Iterable.join?

In Dart, you can concatenate Strings effectively by two ways: you can use StringBuffer class and then convert it to the String, or you can put all of your substrings into the List and then call join('') on them.

I do not understand, what are the pluses of the StringBuffer and why should I use it instead of joining List. Could someone please explain?


There isn't a big difference. If you already have a list of strings, there is no difference in using StringBuffer.writeAll or Iterable.join. The Iterable.join method uses a StringBuffer internaly:

String join([String separator = ""]) {
 StringBuffer buffer = new StringBuffer();
 buffer.writeAll(this, separator);
 return buffer.toString();

From the Dart documentation (click on the code button on the right).

StringBuffer is more efficient as it doesn't create a string object until you call toString.

Seth Lad blogged about the benefits here with some numbers to back it up.

There is a similar blog post about this here.

Need Your Help

Find out constant value by given string in c

c string

Need to check Is the given string constant value (int/long/double) or not?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.