StringBuilder Class

Definition

A mutable sequence of characters.

[Android.Runtime.Register("java/lang/StringBuilder", DoNotGenerateAcw=true)]
public sealed class StringBuilder : Java.Lang.AbstractStringBuilder, IDisposable, Java.Interop.IJavaPeerable, Java.IO.ISerializable, Java.Lang.IComparable, System.Collections.Generic.IEnumerable<char>
[<Android.Runtime.Register("java/lang/StringBuilder", DoNotGenerateAcw=true)>]
type StringBuilder = class
    inherit AbstractStringBuilder
    interface ISerializable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
    interface IAppendable
    interface ICharSequence
    interface seq<char>
    interface IEnumerable
    interface IComparable
Inheritance
Attributes
Implements

Remarks

A mutable sequence of characters. This class provides an API compatible with StringBuffer, but with no guarantee of synchronization. This class is designed for use as a drop-in replacement for StringBuffer in places where the string buffer was being used by a single thread (as is generally the case). Where possible, it is recommended that this class be used in preference to StringBuffer as it will be faster under most implementations.

The principal operations on a StringBuilder are the append and insert methods, which are overloaded so as to accept data of any type. Each effectively converts a given datum to a string and then appends or inserts the characters of that string to the string builder. The append method always adds these characters at the end of the builder; the insert method adds the characters at a specified point.

For example, if z refers to a string builder object whose current contents are "start", then the method call z.append("le") would cause the string builder to contain "startle", whereas z.insert(4, "le") would alter the string builder to contain "starlet".

In general, if sb refers to an instance of a StringBuilder, then sb.append(x) has the same effect as sb.insert(sb.length(), x).

Every string builder has a capacity. As long as the length of the character sequence contained in the string builder does not exceed the capacity, it is not necessary to allocate a new internal buffer. If the internal buffer overflows, it is automatically made larger.

Instances of StringBuilder are not safe for use by multiple threads. If such synchronization is required then it is recommended that java.lang.StringBuffer be used.

Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.

Added in 1.5.

Java documentation for java.lang.StringBuilder.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

StringBuilder()

Constructs a string builder with no characters in it and an initial capacity of 16 characters.

StringBuilder(ICharSequence)

Constructs a string builder that contains the same characters as the specified CharSequence.

StringBuilder(Int32)

Constructs a string builder with no characters in it and an initial capacity specified by the capacity argument.

StringBuilder(String)

Constructs a string builder initialized to the contents of the specified string.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
ThresholdClass (Inherited from AbstractStringBuilder)
ThresholdType (Inherited from AbstractStringBuilder)

Methods

Append(Boolean)

Appends the string representation of the specified boolean value.

Append(Char)

Appends the string representation of the specified char value.

Append(Char[], Int32, Int32)

Appends the string representation of the specified subset of the char[].

Append(Char[])

Appends the string representation of the specified char[].

Append(Double)

Appends the string representation of the specified double value.

Append(ICharSequence, Int32, Int32)

Appends the string representation of the specified subsequence of the CharSequence.

Append(ICharSequence)

Appends the string representation of the specified CharSequence.

Append(Int32)

Appends the string representation of the specified int value.

Append(Int64)

Appends the string representation of the specified long value.

Append(Object)

Appends the string representation of the specified Object.

Append(Single)

Appends the string representation of the specified float value.

Append(String, Int32, Int32)
Append(String)

Appends the contents of the specified string.

Append(StringBuffer)

Appends the specified StringBuffer to this sequence.

AppendCodePoint(Int32)

Added in 1.

Capacity()

Returns the number of characters that can be held without growing.

CharAt(Int32)

Returns the character at index.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
CodePointAt(Int32)

Retrieves the Unicode code point value at the index.

CodePointBefore(Int32)

Retrieves the Unicode code point value that precedes the index.

CodePointCount(Int32, Int32)

Calculates the number of Unicode code points between start and end.

CompareTo(StringBuilder)

Compares two StringBuilder instances lexicographically.

Delete(Int32, Int32)

Deletes a sequence of characters specified by start and end.

DeleteCharAt(Int32)

Deletes the character at the specified index. shifts any remaining characters to the left.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
EnsureCapacity(Int32)

Ensures that this object has a minimum capacity available before requiring the internal buffer to be enlarged.

Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GetChars(Int32, Int32, Char[], Int32)

Copies the requested sequence of characters into dst passed starting at dst.

GetEnumerator()
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
IndexOf(String, Int32)

Searches for the index of the specified character.

IndexOf(String)

Searches for the first index of the specified character.

Insert(Int32, Boolean)

Inserts the string representation of the specified boolean value at the specified offset.

Insert(Int32, Char)

Inserts the string representation of the specified char value at the specified offset.

Insert(Int32, Char[], Int32, Int32)

Inserts the string representation of the specified subsequence of the char[] at the specified offset.

Insert(Int32, Char[])

Inserts the string representation of the specified char[] at the specified offset.

Insert(Int32, Double)

Inserts the string representation of the specified double value at the specified offset.

Insert(Int32, ICharSequence, Int32, Int32)

Inserts the string representation of the specified subsequence of the CharSequence at the specified offset.

Insert(Int32, ICharSequence)

Inserts the string representation of the specified CharSequence at the specified offset.

Insert(Int32, Int32)

Inserts the string representation of the specified int value at the specified offset.

Insert(Int32, Int64)

Inserts the string representation of the specified long value at the specified offset.

Insert(Int32, Object)

Inserts the string representation of the specified Object at the specified offset.

Insert(Int32, Single)

Inserts the string representation of the specified float value at the specified offset.

Insert(Int32, String, Int32, Int32)
Insert(Int32, String)

Inserts the specified string at the specified offset.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
LastIndexOf(String, Int32)

Searches for the index of the specified character.

LastIndexOf(String)

Searches for the last index of the specified character.

Length()

The current length.

Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
OffsetByCodePoints(Int32, Int32)

Returns the index that is offset codePointOffset code points from index.

Replace(Int32, Int32, String)

Replaces the specified subsequence in this builder with the specified string.

Reverse()

Reverses the order of characters in this builder.

SetCharAt(Int32, Char)

Sets the character at the index.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetLength(Int32)

Sets the current length to a new value.

SubSequence(Int32, Int32)
SubSequenceFormatted(Int32, Int32)

Returns a CharSequence of the subsequence from the start index to the end index.

Substring(Int32, Int32)

Returns the String value of the subsequence from the start index to the end index.

Substring(Int32)

Returns the String value of the subsequence from the start index to the current end.

ToArray<T>() (Inherited from Object)
ToString()

Returns the contents of this builder.

TrimToSize()

Trims off any extra capacity beyond the current length.

UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IComparable.CompareTo(Object)
IEnumerable.GetEnumerator()
IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)
Append(IAppendable, String, Int32, Int32)
Append(IAppendable, String)
SubSequence(ICharSequence, Int32, Int32)

Applies to