scala

class StringBuilder

[source: scala/StringBuilder.scala]

@serializable

@SerialVersionUID(-8525408645367278351L)

final class StringBuilder(initCapacity : Int, private initValue : java.lang.String)
extends (Int) => Char

A mutable sequence of characters. This class provides an API compatible with java.lang.StringBuilder.

Author
Stephane Micheloud
Version
1.0
Additional Constructor Summary
def this : StringBuilder
Constructs a string builder with no characters in it and an initial capacity of 16 characters.
def this (capacity : Int) : StringBuilder
Constructs a string builder with no characters in it and an initial capacity specified by the capacity argument.
def this (str : java.lang.String) : StringBuilder
Method Summary
def append (x : Int) : StringBuilder
def append (x : Byte) : StringBuilder
def append (x : Char) : StringBuilder
def append (x : Seq[Char]) : StringBuilder
def append (x : Double) : StringBuilder
def append (x : Array[Char], offset : Int, len : Int) : StringBuilder
def append (s : java.lang.String) : StringBuilder
Appends the specified string to this character sequence.
def append (x : Any) : StringBuilder
def append (x : Short) : StringBuilder
def append (x : Boolean) : StringBuilder
def append (x : Long) : StringBuilder
def append (sb : StringBuilder) : StringBuilder
Appends the specified string builder to this sequence.
def append (x : Float) : StringBuilder
def append (x : Array[Char]) : StringBuilder
def apply (i : Int) : Char
Same as charAt.
def capacity : Int
Returns the current capacity. The capacity is the amount of storage available for newly inserted characters, beyond which an allocation will occur.
def capacity_= (n : Int) : Unit
Same as ensureCapacity.
def charAt (index : Int) : Char
def delete (start : Int, end : Int) : StringBuilder
Removes the characters in a substring of this sequence. The substring begins at the specified start and extends to the character at index end - 1 or to the end of the sequence if no such character exists. If start is equal to end, no changes are made.
def deleteCharAt (index : Int) : StringBuilder
def ensureCapacity (n : Int) : Unit
def indexOf (str : java.lang.String) : Int
def indexOf (str : java.lang.String, fromIndex : Int) : Int
def insert (at : Int, x : Any) : StringBuilder
def insert (at : Int, x : Long) : StringBuilder
def insert (at : Int, x : Float) : StringBuilder
def insert (at : Int, x : Short) : StringBuilder
def insert (at : Int, x : Int) : StringBuilder
def insert (index : Int, str : Array[Char], offset : Int, len : Int) : StringBuilder
Inserts the string representation of a subarray of the str array argument into this sequence. The subarray begins at the specified offset and extends len chars. The characters of the subarray are inserted into this sequence at the position indicated by index. The length of this sequence increases by len Chars.
def insert (at : Int, x : Char) : StringBuilder
def insert (at : Int, x : Byte) : StringBuilder
def insert (at : Int, x : Boolean) : StringBuilder
def insert (at : Int, x : java.lang.String) : StringBuilder
Inserts the string into this character sequence.
def insert (at : Int, x : Double) : StringBuilder
def insert (at : Int, x : Seq[Char]) : StringBuilder
Inserts the string representation of the Char sequence argument into this sequence.
def insert (at : Int, x : Array[Char]) : StringBuilder
Inserts the string representation of the Char array argument into this sequence.
def lastIndexOf (str : java.lang.String, fromIndex : Int) : Int
def lastIndexOf (str : java.lang.String) : Int
def length : Int
def length_= (n : Int) : Unit
def replace (start : Int, end : Int, str : java.lang.String) : Unit
Replaces the characters in a substring of this sequence with characters in the specified String. The substring begins at the specified start and extends to the character at index end - 1 or to the end of the sequence if no such character exists. First the characters in the substring are removed and then the specified String is inserted at start.
def reverse : StringBuilder
def setCharAt (index : Int, ch : Char) : Unit
def setLength (n : Int) : Unit
Sets the length of the character sequence.
def substring (start : Int, end : Int) : java.lang.String
Returns a new String that contains a subsequence of characters currently contained in this sequence. The substring begins at the specified start and extends to the character at index end - 1.
def substring (start : Int) : java.lang.String
Returns a new String that contains a subsequence of characters currently contained in this character sequence. The substring begins at the specified index and extends to the end of this sequence.
def toArray : Array[Char]
override def toString : java.lang.String
Returns a string representing the data in this sequence. A new String object is allocated and initialized to contain the character sequence currently represented by this object. This String is then returned. Subsequent changes to this sequence do not affect the contents of the String.
def update (i : Int, c : Char) : Unit
Same as setCharAt.
Methods inherited from Function1
compose, andThen
Methods inherited from AnyRef
getClass, hashCode, equals, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Additional Constructor Details
def this : StringBuilder
Constructs a string builder with no characters in it and an initial capacity of 16 characters.

def this(capacity : Int) : StringBuilder
Constructs a string builder with no characters in it and an initial capacity specified by the capacity argument.
Parameters
capacity - the initial capacity.
Throws
NegativeArraySizeException - if the capacity argument is less than 0.

def this(str : java.lang.String) : StringBuilder

Method Details
def toArray : Array[Char]

def length : Int

def length_=(n : Int) : Unit

def setLength(n : Int) : Unit
Sets the length of the character sequence.
Parameters
newLength - the new length
Throws
IndexOutOfBoundsException - if the n argument is negative.

def capacity : Int
Returns the current capacity. The capacity is the amount of storage available for newly inserted characters, beyond which an allocation will occur.
Returns
the current capacity

def capacity_=(n : Int) : Unit
Same as ensureCapacity.

def ensureCapacity(n : Int) : Unit

Ensures that the capacity is at least equal to the specified minimum. If the current capacity is less than the argument, then a new internal array is allocated with greater capacity. The new capacity is the larger of:

  • The n argument.
  • Twice the old capacity, plus 2.

If the n argument is non-positive, this method takes no action and simply returns.

Parameters
n - the minimum desired capacity.

def charAt(index : Int) : Char

Returns the Char value in this sequence at the specified index. The first Char value is at index 0, the next at index 1, and so on, as in array indexing.

The index argument must be greater than or equal to 0, and less than the length of this sequence.

Parameters
index - the index of the desired Char value.
Returns
the Char value at the specified index.
Throws
IndexOutOfBoundsException - if index is negative or greater than or equal to length().

def apply(i : Int) : Char
Same as charAt.
Overrides
Function1.apply

def deleteCharAt(index : Int) : StringBuilder

Removes the Char at the specified position in this sequence. This sequence is shortened by one Char.

Parameters
index - Index of Char to remove
Returns
This object.
Throws
StringIndexOutOfBoundsException - if the index is negative or greater than or equal to length().

def setCharAt(index : Int, ch : Char) : Unit

The character at the specified index is set to ch. This sequence is altered to represent a new character sequence that is identical to the old character sequence, except that it contains the character ch at position index.

The index argument must be greater than or equal to 0, and less than the length of this sequence.

Parameters
index - the index of the character to modify.
ch - the new character.
Throws
IndexOutOfBoundsException - if index is negative or greater than or equal to length().

def update(i : Int, c : Char) : Unit
Same as setCharAt.

def substring(start : Int) : java.lang.String
Returns a new String that contains a subsequence of characters currently contained in this character sequence. The substring begins at the specified index and extends to the end of this sequence.
Parameters
start - The beginning index, inclusive.
Returns
The new string.
Throws
StringIndexOutOfBoundsException - if start is less than zero, or greater than the length of this object.

def substring(start : Int, end : Int) : java.lang.String
Returns a new String that contains a subsequence of characters currently contained in this sequence. The substring begins at the specified start and extends to the character at index end - 1.
Parameters
start - The beginning index, inclusive.
end - The ending index, exclusive.
Returns
The new string.
Throws
StringIndexOutOfBoundsException - if start or end are negative or greater than length(), or start is greater than end.

def append(x : Any) : StringBuilder

Appends the string representation of the Any argument.

The argument is converted to a string as if by the method String.valueOf, and the characters of that string are then appended to this sequence.

Parameters
x - an Any object.
Returns
a reference to this object.

def append(s : java.lang.String) : StringBuilder
Appends the specified string to this character sequence.
Parameters
s - a string.
Returns
a reference to this object.

def append(sb : StringBuilder) : StringBuilder
Appends the specified string builder to this sequence.
Parameters
sb -
Returns

def append(x : Seq[Char]) : StringBuilder

Appends the string representation of the Char sequence argument to this sequence.

The characters of the sequence argument are appended, in order, to the contents of this sequence. The length of this sequence increases by the length of the argument.

Parameters
x - the characters to be appended.
Returns
a reference to this object.

def append(x : Array[Char]) : StringBuilder

Appends the string representation of the Char array argument to this sequence.

The characters of the array argument are appended, in order, to the contents of this sequence. The length of this sequence increases by the length of the argument.

Parameters
x - the characters to be appended.
Returns
a reference to this object.

def append(x : Array[Char], offset : Int, len : Int) : StringBuilder

Appends the string representation of a subarray of the char array argument to this sequence.

Characters of the Char array x, starting at index offset, are appended, in order, to the contents of this sequence. The length of this sequence increases by the value of len.

Parameters
x - the characters to be appended.
offset - the index of the first Char to append.
len - the number of Chars to append.
Returns
a reference to this object.

def append(x : Boolean) : StringBuilder

Appends the string representation of the Boolean argument to the sequence.

The argument is converted to a string as if by the method String.valueOf, and the characters of that string are then appended to this sequence.

Parameters
x - a Boolean.
Returns
a reference to this object.

def append(x : Byte) : StringBuilder

def append(x : Char) : StringBuilder

def append(x : Short) : StringBuilder

def append(x : Int) : StringBuilder

def append(x : Long) : StringBuilder

def append(x : Float) : StringBuilder

def append(x : Double) : StringBuilder

def delete(start : Int, end : Int) : StringBuilder
Removes the characters in a substring of this sequence. The substring begins at the specified start and extends to the character at index end - 1 or to the end of the sequence if no such character exists. If start is equal to end, no changes are made.
Parameters
start - The beginning index, inclusive.
end - The ending index, exclusive.
Returns
This object.
Throws
StringIndexOutOfBoundsException - if start is negative, greater than length(), or greater than end.

def replace(start : Int, end : Int, str : java.lang.String) : Unit
Replaces the characters in a substring of this sequence with characters in the specified String. The substring begins at the specified start and extends to the character at index end - 1 or to the end of the sequence if no such character exists. First the characters in the substring are removed and then the specified String is inserted at start.
Parameters
start - The beginning index, inclusive.
end - The ending index, exclusive.
str - String that will replace previous contents.
Returns
This object.
Throws
StringIndexOutOfBoundsException - if start is negative, greater than length(), or greater than end.

def insert(index : Int, str : Array[Char], offset : Int, len : Int) : StringBuilder
Inserts the string representation of a subarray of the str array argument into this sequence. The subarray begins at the specified offset and extends len chars. The characters of the subarray are inserted into this sequence at the position indicated by index. The length of this sequence increases by len Chars.
Parameters
index - position at which to insert subarray.
str - a Char array.
offset - the index of the first char in subarray to be inserted.
len - the number of Chars in the subarray to be inserted.
Returns
This object
Throws
StringIndexOutOfBoundsException - if index is negative or greater than length(), or offset or len are negative, or (offset+len) is greater than str.length.

def insert(at : Int, x : Any) : StringBuilder

Inserts the string representation of the Any argument into this character sequence.

The second argument is converted to a string as if by the method String.valueOf, and the characters of that string are then inserted into this sequence at the indicated offset.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this sequence.

Parameters
offset - the offset.
x - an Any value.
Returns
a reference to this object.
Throws
StringIndexOutOfBoundsException - if the offset is invalid.

def insert(at : Int, x : java.lang.String) : StringBuilder
Inserts the string into this character sequence.
Parameters
at - the offset position.
x - a string.
Returns
a reference to this object.
Throws
StringIndexOutOfBoundsException - if the offset is invalid.

def insert(at : Int, x : Seq[Char]) : StringBuilder
Inserts the string representation of the Char sequence argument into this sequence.
Parameters
at - the offset position.
x - a character sequence.
Returns
a reference to this object.
Throws
StringIndexOutOfBoundsException - if the offset is invalid.

def insert(at : Int, x : Array[Char]) : StringBuilder
Inserts the string representation of the Char array argument into this sequence.
Parameters
at - the offset position.
x - a character array.
Returns
a reference to this object.
Throws
StringIndexOutOfBoundsException - if the offset is invalid.

def insert(at : Int, x : Boolean) : StringBuilder

Inserts the string representation of the Boolean argument into this sequence.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this sequence.

Parameters
at - the offset position.
x - a Boolean value.
Returns
a reference to this object.

def insert(at : Int, x : Byte) : StringBuilder

Inserts the string representation of the Byte argument into this sequence.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this sequence.

Parameters
at - the offset position.
x - a Byte value.
Returns
a reference to this object.

def insert(at : Int, x : Char) : StringBuilder

Inserts the string representation of the Char argument into this sequence.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this sequence.

Parameters
at - the offset position.
x - a Char value.
Returns
a reference to this object.

def insert(at : Int, x : Short) : StringBuilder

Inserts the string representation of the Short argument into this sequence.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this sequence.

Parameters
at - the offset position.
x - a Short value.
Returns
a reference to this object.

def insert(at : Int, x : Int) : StringBuilder

Inserts the string representation of the Int argument into this sequence.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this sequence.

Parameters
at - the offset position.
x - a Int value.
Returns
a reference to this object.

def insert(at : Int, x : Long) : StringBuilder

Inserts the string representation of the Long argument into this sequence.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this sequence.

Parameters
at - the offset position.
x - a Long value.
Returns
a reference to this object.

def insert(at : Int, x : Float) : StringBuilder

Inserts the string representation of the Float argument into this sequence.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this sequence.

Parameters
at - the offset position.
x - a Float value.
Returns
a reference to this object.

def insert(at : Int, x : Double) : StringBuilder

Inserts the string representation of the Double argument into this sequence.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this sequence.

Parameters
at - the offset position.
x - a Double value.
Returns
a reference to this object.

def indexOf(str : java.lang.String) : Int

Returns the index within this string of the first occurrence of the specified substring. The integer returned is the smallest value k such that:

    this.toString().startsWith(str, k)

is true.

Parameters
str - any string.
Returns
if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned.
Throws
NullPointerException - if str is null.

def indexOf(str : java.lang.String, fromIndex : Int) : Int

Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. The integer returned is the smallest value k for which:

      k >= Math.min(fromIndex, str.length()) &&
                     this.toString().startsWith(str, k)

If no such value of k exists, then -1 is returned.

Parameters
str - the substring for which to search.
fromIndex - the index from which to start the search.
Returns
the index within this string of the first occurrence of the specified substring, starting at the specified index.

def lastIndexOf(str : java.lang.String) : Int

Returns the index within this string of the rightmost occurrence of the specified substring. The rightmost empty string "" is considered to occur at the index value this.length(). The returned index is the largest value k such that

    this.toString().startsWith(str, k)

is true.

Parameters
str - the substring to search for.
Returns
if the string argument occurs one or more times as a substring within this object, then the index of the first character of the last such substring is returned. If it does not occur as a substring, -1 is returned.
Throws
NullPointerException - if str is null.

def lastIndexOf(str : java.lang.String, fromIndex : Int) : Int

Returns the index within this string of the last occurrence of the specified substring. The integer returned is the largest value k such that:

      k <= Math.min(fromIndex, str.length()) &&
                     this.toString().startsWith(str, k)

If no such value of k exists, then -1 is returned.

Parameters
str - the substring to search for.
fromIndex - the index to start the search from.
Returns
the index within this sequence of the last occurrence of the specified substring.

def reverse : StringBuilder

Causes this character sequence to be replaced by the reverse of the sequence. If there are any surrogate pairs included in the sequence, these are treated as single characters for the reverse operation. Thus, the order of the high-low surrogates is never reversed.

Let n be the character length of this character sequence (not the length in Char values) just prior to execution of the reverse method. Then the character at index k in the new character sequence is equal to the character at index n-k-1 in the old character sequence.

Returns
a reference to this object.

override def toString : java.lang.String
Returns a string representing the data in this sequence. A new String object is allocated and initialized to contain the character sequence currently represented by this object. This String is then returned. Subsequent changes to this sequence do not affect the contents of the String.
Returns
a string representation of this sequence of characters.
Overrides
Function1.toString