Scala Library
|
|
scala/StringBuilder.scala
]
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
.
Additional Constructor Summary | |
def
|
this (str : java.lang.String) : StringBuilder |
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. |
Method Summary | |
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 : Float) : StringBuilder |
def
|
append (x : Array[Char]) : StringBuilder |
def
|
append (x : Double) : StringBuilder |
def
|
append
(sb : StringBuilder) : StringBuilder
Appends the specified string builder to this sequence.
|
def
|
append (x : Seq[Char]) : StringBuilder |
def
|
append (x : Short) : StringBuilder |
def
|
append (x : Byte) : StringBuilder |
def
|
append (x : Long) : StringBuilder |
def
|
append (x : Boolean) : StringBuilder |
def
|
append (x : Any) : StringBuilder |
def
|
append (x : Int) : StringBuilder |
def
|
append (x : 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 : Seq[Char]) : StringBuilder
Inserts the string representation of the
Char sequence
argument into this sequence. |
def
|
insert (at : Int, x : Short) : 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 char s.
The characters of the subarray are inserted into this sequence at
the position indicated by index . The length of this
sequence increases by len Char s. |
def
|
insert (at : Int, x : Byte) : StringBuilder |
def
|
insert
(at : Int, x : Array[Char]) : StringBuilder
Inserts the string representation of the
Char array
argument into this sequence. |
def
|
insert (at : Int, x : Double) : StringBuilder |
def
|
insert (at : Int, x : Long) : StringBuilder |
def
|
insert (at : Int, x : Int) : StringBuilder |
def
|
insert (at : Int, x : Float) : StringBuilder |
def
|
insert (at : Int, x : Char) : StringBuilder |
def
|
insert
(at : Int, x : java.lang.String) : StringBuilder
Inserts the string into this character sequence.
|
def
|
insert (at : Int, x : Boolean) : StringBuilder |
def
|
lastIndexOf (str : java.lang.String) : Int |
def
|
lastIndexOf (str : java.lang.String, fromIndex : Int) : 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
def
this(capacity : Int) : StringBuilder
capacity
argument.capacity -
the initial capacity.NegativeArraySizeException -
if the capacity
argument is less than 0
.
def
this(str : java.lang.String) : StringBuilder
Method Details |
def
length : Int
newLength -
the new lengthIndexOutOfBoundsException -
if the n
argument is negative.
def
capacity : Int
ensureCapacity
.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:
n
argument.
2
.
If the n
argument is non-positive, this
method takes no action and simply returns.
n -
the minimum desired capacity.
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.
index -
the index of the desired Char
value.Char
value at the specified index.IndexOutOfBoundsException -
if index
is negative or greater than or equal to length()
.charAt
.
def
deleteCharAt(index : Int) : StringBuilder
Removes the Char
at the specified position in this
sequence. This sequence is shortened by one Char
.
index -
Index of Char
to removeStringIndexOutOfBoundsException -
if the index
is negative or greater than or equal to length()
.
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.
index -
the index of the character to modify.ch -
the new character.IndexOutOfBoundsException -
if index
is negative or greater than or equal to length()
.setCharAt
.
def
substring(start : Int) : java.lang.String
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.start -
The beginning index, inclusive.StringIndexOutOfBoundsException -
if start
is less than zero, or greater than the length of this object.
def
substring(start : Int, end : Int) : java.lang.String
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
.start -
The beginning index, inclusive.end -
The ending index, exclusive.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.
x -
an Any
object.
def
append(s : java.lang.String) : StringBuilder
s -
a string.
def
append(sb : StringBuilder) : StringBuilder
sb -
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.
x -
the characters to be appended.
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.
x -
the characters to be appended.
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
.
x -
the characters to be appended.offset -
the index of the first Char
to append.len -
the number of Char
s to append.
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.
x -
a Boolean
.
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
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.start -
The beginning index, inclusive.end -
The ending index, exclusive.StringIndexOutOfBoundsException -
if start
is negative, greater than length()
, or
greater than end
.
def
replace(start : Int, end : Int, str : java.lang.String) : Unit
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
.start -
The beginning index, inclusive.end -
The ending index, exclusive.str -
String that will replace previous contents.StringIndexOutOfBoundsException -
if start
is negative, greater than length()
, or
greater than end
.str
array argument into this sequence. The subarray begins at the specified
offset
and extends len
char
s.
The characters of the subarray are inserted into this sequence at
the position indicated by index
. The length of this
sequence increases by len
Char
s.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 Char
s in the subarray to be inserted.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.
offset -
the offset.x -
an Any
value.StringIndexOutOfBoundsException -
if the offset is invalid.
def
insert(at : Int, x : java.lang.String) : StringBuilder
at -
the offset position.x -
a string.StringIndexOutOfBoundsException -
if the offset is invalid.
def
insert(at : Int, x : Seq[Char]) : StringBuilder
Char
sequence
argument into this sequence.at -
the offset position.x -
a character sequence.StringIndexOutOfBoundsException -
if the offset is invalid.
def
insert(at : Int, x : Array[Char]) : StringBuilder
Char
array
argument into this sequence.at -
the offset position.x -
a character array.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.
at -
the offset position.x -
a Boolean
value.
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.
at -
the offset position.x -
a Byte
value.
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.
at -
the offset position.x -
a Char
value.
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.
at -
the offset position.x -
a Short
value.
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.
at -
the offset position.x -
a Int
value.
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.
at -
the offset position.x -
a Long
value.
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.
at -
the offset position.x -
a Float
value.
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.
at -
the offset position.x -
a Double
value.
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
.
str -
any string.-1
is returned.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.
str -
the substring for which to search.fromIndex -
the index from which to start the search.
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.
str -
the substring to search for.-1
is returned.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.
str -
the substring to search for.fromIndex -
the index to start the search from.
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.
override
def
toString : java.lang.String
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
.
Scala Library
|
|