Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart's equivalent for Java's StringBuilder

Tags:

dart

Is there a Dart equivalent for Java's StringBuilder?

I have looked into StringBuffer, but that API doesn't have as many features as the StringBuilder. Methods like delete, reverse or variety for insert are missing in the StringBuffer.

Follow-up - request feature

like image 291
Eternalcode Avatar asked Mar 01 '16 20:03

Eternalcode


People also ask

What is the best for using StringBuilder instead of string?

String is immutable whereas StringBuffer and StringBuilder are mutable classes. StringBuffer is thread-safe and synchronized whereas StringBuilder is not. That's why StringBuilder is faster than StringBuffer.

How do I add a character to a StringBuilder in Java?

append(char c) method appends the string representation of the char argument to this sequence. The argument is appended to the contents of this sequence. The length of this sequence increases by 1.

Why is StringBuilder better than string Java?

StringBuilder is speedy and consumes less memory than a string while performing concatenations. This is because string is immutable in Java, and concatenation of two string objects involves creating a new object.


1 Answers

Dart names them differently

insert becomes write delete becomes clear

for reverse you can call toString and then reverse.

Example:

  var buffer = new StringBuffer();    buffer.write("Hello");   buffer.write("world");    print(buffer.toString());   print(buffer.toString().split('').reversed.join()); 
like image 64
giannisf Avatar answered Oct 26 '22 15:10

giannisf