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
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.
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.
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.
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With