StringBuilder class final

A mutable sequence of characters similar to Java's StringBuilder.

This class provides an efficient way to build strings by appending characters, strings, and other data types.

Example usage:

StringBuilder sb = StringBuilder();
sb.append("Hello");
sb.append(" ");
sb.append("World");
sb.append("!");

print(sb.toString()); // "Hello World!"
print(sb.length()); // 12

Constructors

StringBuilder()
Creates an empty StringBuilder.
StringBuilder.withCapacity(int capacity)
Creates a StringBuilder with initial capacity (ignored in Dart).
StringBuilder.withContent(String initialContent)
Creates a StringBuilder with initial content.

Properties

capacity int
Returns the current capacity (same as length in Dart).
no setter
hashCode int
Returns the hash code for this StringBuilder.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

append(dynamic str) StringBuilder
Appends a string to this StringBuilder.
appendAll(Iterable<Object?> objects, [String separator = '']) StringBuilder
Appends all elements from an iterable.
appendBool(bool value) StringBuilder
Appends a boolean to this StringBuilder.
appendChar(String char) StringBuilder
Appends a character to this StringBuilder.
appendCharCode(int charCode) StringBuilder
Appends a character code.
appendDouble(double value) StringBuilder
Appends a double to this StringBuilder.
appendInt(int value) StringBuilder
Appends an integer to this StringBuilder.
appendLine([String? str]) StringBuilder
Appends a line separator to this StringBuilder.
appendObject(Object? obj) StringBuilder
Appends an object's string representation to this StringBuilder.
charAt(int index) String
Returns the character at the specified index.
clear() StringBuilder
Clears the contents of this StringBuilder.
delete(int start, int end) StringBuilder
Deletes characters from the specified range.
deleteCharAt(int index) StringBuilder
Deletes the character at the specified index.
ensureCapacity(int minimumCapacity) → void
Ensures that the capacity is at least the specified minimum.
indexOf(String str, [int start = 0]) int
Returns the index of the first occurrence of the specified string.
insert(int index, String str) StringBuilder
Inserts a string at the specified index.
isEmpty() bool
Returns true if this StringBuilder is empty.
isNotEmpty() bool
Returns true if this StringBuilder is not empty.
lastIndexOf(String str, [int? start]) int
Returns the index of the last occurrence of the specified string.
length() int
Returns the length of this StringBuilder.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
replace(int start, int end, String str) StringBuilder
Replaces characters in the specified range with the given string.
reverse() StringBuilder
Reverses the contents of this StringBuilder.
setCharAt(int index, String char) → void
Sets the character at the specified index.
setLength(int newLength) → void
Sets the length of this StringBuilder.
substring(int start, [int? end]) String
Returns a substring of this StringBuilder.
toString() String
Returns the string representation of this StringBuilder.
override
trim() StringBuilder
Trims whitespace from the beginning and end.
trimToSize() StringBuilder
Trims the capacity to the current length.

Operators

operator +(Object other) StringBuilder
Addition operator for appending
operator ==(Object other) bool
Returns true if this StringBuilder equals the specified object.
override
operator [](int index) String
Operator overloads
operator []=(int index, String char) → void