- 浏览: 11715992 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
笨蛋咯:
获取不到信息?
C#枚举硬件设备 -
guokaiwhu:
能把plan的数据结构图画出来,博主的耐心和细致令人佩服。
PostgreSQL服务过程中的那些事二:Pg服务进程处理简单查询五:规划成plantree -
gao807877817:
学习
BitmapFactory.Options详解 -
GB654:
楼主,我想问一下,如何在创建PPT时插入备注信息,虽然可以解析 ...
java转换ppt,ppt转成图片,获取备注,获取文本 -
jpsb:
多谢 ,不过我照搬你的sql查不到,去掉utl_raw.cas ...
关于oracle中clob字段查询的问题
StringBuffer
|
Java™ Platform Standard Ed. 6 |
||||||||
PREV CLASSNEXT CLASS | FRAMESNO FRAMESAll Classes | ||||||||
SUMMARY: NESTED | FIELD |CONSTR|METHOD | DETAIL: FIELD |CONSTR|METHOD |
java.lang
Class StringBuffer
java.lang.Objectjava.lang.StringBuffer
public final classStringBuffer
Athread-safe(线程安全), mutable sequence of characters. A string buffer(缓冲区) is like aString
, but can bemodified(修改). At any point in time it contains some(某些) particular(特定的)
sequence of characters, but the length and content of the sequence can be changed through certain(某些) method calls.
String buffers are safe for use bymultiple threads(多线程). The methods are synchronized(同步) where necessary(必要)so that(所以) all the operations(操作) on any particular(特定) instance behave as(像) if they occur(发生) in someserial(串行的) order(序列) that isconsistent with(一致) the order(顺序) of themethod calls(调用方法) made byeach of the individual(每个独立的) threads involved(涉及的).
Theprincipal(最重要的) operations on aStringBuffer
are theappend
andinsert
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 buffer. Theappend
method always adds these characters at the end(末端) of the buffer; theinsert
method adds the characters at a specified point.
For example, ifz
refers(属于) to a string buffer object whose current contents are "start
", then the method callz.append("le")
would cause the string buffer to contain "startle
",whereas(反之)z.insert(4,
"le")
would alter the string buffer to contain "starlet
".
In general(情况下), if sb refers to an instance of aStringBuffer
, thensb.append(x)
has the same effect(效果) assb.insert(sb.length(), x)
.
Whenever an operationoccurs involving(有关的) a source sequence (such as appending or inserting from a source sequence) this class synchronizes(同步) only on the string buffer performing(执行) the operation, not on the source.
Every string buffer has a capacity(容量). As long as the length of the character sequence contained in the string buffer does not exceed(超过) the capacity, it is not necessary toallocate(分配)a newinternal(内部) buffer array. If
the internal buffer overflows(溢出), it isautomatically(自动的)made larger(增大). As of release(发布) JDK 5, this class has been supplemented(增加) with anequivalent class(等价类) designed for use by a single thread,StringBuilder
.
TheStringBuilderclass shouldgenerally(一般) be used in preference(优先) to this one, as it supports all of the same operations but it is faster(更快的), as it performs(执行) no synchronization.
StringBuilder
,String
,Serialized Form
StringBuffer() Constructs a string buffer with no characters in it and an initial capacity of 16 characters. |
StringBuffer(CharSequenceseq) Constructs a string buffer that contains the same characters as the specified CharSequence . |
StringBuffer(int capacity) Constructs a string buffer with no characters in it and the specified initial capacity. |
StringBuffer(Stringstr) Constructs a string buffer initialized to the contents of the specified string. |
StringBuffer
|
append(boolean b) Appends the string representation of the boolean argument to the sequence. |
StringBuffer
|
append(char c) Appends the string representation of the char argument to this sequence. |
StringBuffer
|
append(char[] str) Appends the string representation of the char array argument to this sequence. |
StringBuffer
|
append(char[] str, int offset, int len) Appends the string representation of a subarray of the char array argument to this sequence. |
StringBuffer
|
append(CharSequences) Appends the specified CharSequence to this sequence. |
StringBuffer
|
append(CharSequences, int start, int end) Appends a subsequence of the specified CharSequence to this sequence. |
StringBuffer
|
append(double d) Appends the string representation of the double argument to this sequence. |
StringBuffer
|
append(float f) Appends the string representation of the float argument to this sequence. |
StringBuffer
|
append(int i) Appends the string representation of the int argument to this sequence. |
StringBuffer
|
append(long lng) Appends the string representation of the long argument to this sequence. |
StringBuffer
|
append(Objectobj) Appends the string representation of the Object argument. |
StringBuffer
|
append(Stringstr) Appends the specified string to this character sequence. |
StringBuffer
|
append(StringBuffersb) Appends the specifiedStringBufferto this sequence. |
StringBuffer
|
appendCodePoint(int codePoint) Appends the string representation of the codePoint argument to this sequence. |
int
|
capacity() Returns the current capacity. |
char
|
charAt(int index) Returns the char value in this sequence at the specified index. |
int
|
codePointAt(int index) Returns the character (Unicode code point) at the specified index. |
int
|
codePointBefore(int index) Returns the character (Unicode code point) before the specified index. |
int
|
codePointCount(int beginIndex, int endIndex) Returns the number of Unicode code points in the specified text range of this sequence. |
StringBuffer
|
delete(int start, int end) Removes the characters in a substring of this sequence. |
StringBuffer
|
deleteCharAt(int index) Removes the char at the specified position in this sequence. |
void
|
ensureCapacity(int minimumCapacity) Ensures that the capacity is at least equal to the specified minimum. |
void
|
getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) Characters are copied from this sequence into the destination character array dst . |
int
|
indexOf(Stringstr) Returns the index within this string of the first occurrence of the specified substring. |
int
|
indexOf(Stringstr, int fromIndex) Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. |
StringBuffer
|
insert(int offset, boolean b) Inserts the string representation of the boolean argument into this sequence. |
StringBuffer
|
insert(int offset, char c) Inserts the string representation of the char argument into this sequence. |
StringBuffer
|
insert(int offset, char[] str) Inserts the string representation of the char array argument into this sequence. |
StringBuffer
|
insert(int index, char[] str, int offset, int len) Inserts the string representation of a subarray of the str array argument into this sequence. |
StringBuffer
|
insert(int dstOffset,CharSequences) Inserts the specified CharSequence into this sequence. |
StringBuffer
|
insert(int dstOffset,CharSequences, int start, int end) Inserts a subsequence of the specified CharSequence into this sequence. |
StringBuffer
|
insert(int offset, double d) Inserts the string representation of the double argument into this sequence. |
StringBuffer
|
insert(int offset, float f) Inserts the string representation of the float argument into this sequence. |
StringBuffer
|
insert(int offset, int i) Inserts the string representation of the second int argument into this sequence. |
StringBuffer
|
insert(int offset, long l) Inserts the string representation of the long argument into this sequence. |
StringBuffer
|
insert(int offset,Objectobj) Inserts the string representation of the Object argument into this character sequence. |
StringBuffer
|
insert(int offset,Stringstr) Inserts the string into this character sequence. |
int
|
lastIndexOf(Stringstr) Returns the index within this string of the rightmost occurrence of the specified substring. |
int
|
lastIndexOf(Stringstr, int fromIndex) Returns the index within this string of the last occurrence of the specified substring. |
int
|
length() Returns the length (character count). |
int
|
offsetByCodePoints(int index, int codePointOffset) Returns the index within this sequence that is offset from the given index bycodePointOffset code points. |
StringBuffer
|
replace(int start, int end,Stringstr) Replaces the characters in a substring of this sequence with characters in the specified String . |
StringBuffer
|
reverse() Causes this character sequence to be replaced by the reverse of the sequence. |
void
|
setCharAt(int index, char ch) The character at the specified index is set to ch . |
void
|
setLength(int newLength) Sets the length of the character sequence. |
CharSequence
|
subSequence(int start, int end) Returns a new character sequence that is a subsequence of this sequence. |
String
|
substring(int start) Returns a new String that contains a subsequence of characters currently contained in this character sequence. |
String
|
substring(int start, int end) Returns a new String that contains a subsequence of characters currently contained in this sequence. |
String
|
toString() Returns a string representing the data in this sequence. |
void
|
trimToSize() Attempts to reduce storage used for the character sequence. |
clone,equals,finalize,getClass,hashCode,notify,notifyAll,wait,wait,wait |
StringBuffer
publicStringBuffer()
StringBuffer
publicStringBuffer(int capacity)
capacity
- the initial capacity.NegativeArraySizeException
- if thecapacity
argument is less than0
.StringBuffer
publicStringBuffer(Stringstr)
16
plus the length of the string argument.
str
- the initial contents of the buffer.NullPointerException
- ifstr
isnull
StringBuffer
publicStringBuffer(CharSequenceseq)
CharSequence
. The initial capacity of the string buffer is16
plus the length of theCharSequence
argument.
If the length of the specifiedCharSequence
is less than or equal to zero, then an empty buffer of capacity16
is returned.
seq
- the sequence to copy.NullPointerException
- ifseq
isnull
length
public intlength()
length
in interfaceCharSequence
capacity
public intcapacity()
ensureCapacity
public voidensureCapacity(int minimumCapacity)
- The
minimumCapacity
argument. - Twice the old capacity, plus
2
.
minimumCapacity
argument is nonpositive, this method takes no action and simply returns.minimumCapacity
- the minimum desired capacity.trimToSize
public voidtrimToSize()
capacity()
method.setLength
public voidsetLength(int newLength)
newLength
, the character at indexkin the new
character sequence is the same as the character at indexkin the old sequence ifkis less than the length of the old character sequence; otherwise, it is the null character'\u0000'
. In other words, if thenewLength
argument
is less than the current length, the length is changed to the specified length.
If thenewLength
argument is greater than or equal to the current length, sufficient null characters ('\u0000'
) are appended so that length becomes thenewLength
argument.
ThenewLength
argument must be greater than or equal to0
.
newLength
- the new lengthIndexOutOfBoundsException
- if thenewLength
argument is negative.length()
charAt
public charcharAt(int index)
char
value in this sequence at the specified index. The firstchar
value is at index0
, the next at index1
, and so on, as in array indexing.
The index argument must be greater than or equal to0
, and less than the length of this sequence.
If thechar
value specified by the index is asurrogate, the surrogate value is returned.
charAt
in interfaceCharSequence
index
- the index of the desiredchar
value.char
value at the specified index.IndexOutOfBoundsException
- ifindex
is negative or greater than or equal tolength()
.length()
codePointAt
public intcodePointAt(int index)
char
values (Unicode code units) and ranges from0
tolength()
- 1
.
If thechar
value specified at the given index is in the high-surrogate range, the following index is less than the length of this sequence, and thechar
value at the following index is in the low-surrogate range, then the supplementary
code point corresponding to this surrogate pair is returned. Otherwise, thechar
value at the given index is returned.
index
- the index to thechar
valuesindex
codePointBefore
public intcodePointBefore(int index)
char
values (Unicode code units) and ranges from1
tolength()
.
If thechar
value at(index - 1)
is in the low-surrogate range,(index - 2)
is not negative, and thechar
value at(index - 2)
is in the high-surrogate range, then the supplementary code point
value of the surrogate pair is returned. If thechar
value atindex - 1
is an unpaired low-surrogate or a high-surrogate, the surrogate value is returned.
index
- the index following the code point that should be returnedcodePointCount
public intcodePointCount(int beginIndex, int endIndex)
beginIndex
and extends to thechar
at indexendIndex - 1
. Thus the length (inchar
s)
of the text range isendIndex-beginIndex
. Unpaired surrogates within this sequence count as one code point each.beginIndex
- the index to the firstchar
of the text range.endIndex
- the index after the lastchar
of the text range.offsetByCodePoints
public intoffsetByCodePoints(int index, int codePointOffset)
index
bycodePointOffset
code points. Unpaired surrogates within the text range given byindex
andcodePointOffset
count as one code point
each.index
- the index to be offsetcodePointOffset
- the offset in code pointsgetChars
public voidgetChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
dst
. The first character to be copied is at indexsrcBegin
; the last character to be copied is at indexsrcEnd-1
. The total number of characters
to be copied issrcEnd-srcBegin
. The characters are copied into the subarray ofdst
starting at indexdstBegin
and ending at index:
dstbegin + (srcEnd-srcBegin) - 1
srcBegin
- start copying at this offset.srcEnd
- stop copying at this offset.dst
- the array to copy the data into.dstBegin
- offset intodst
.NullPointerException
- ifdst
isnull
.IndexOutOfBoundsException
- if any of the following is true:
-
srcBegin
is negative -
dstBegin
is negative - the
srcBegin
argument is greater than thesrcEnd
argument. -
srcEnd
is greater thanthis.length()
. -
dstBegin+srcEnd-srcBegin
is greater thandst.length
setCharAt
public voidsetCharAt(int index, char ch)
ch
. This sequence is altered to represent a new character sequence that is identical to the old character sequence, except that it contains the characterch
at positionindex
.
The index argument must be greater than or equal to0
, and less than the length of this sequence.
index
- the index of the character to modify.ch
- the new character.IndexOutOfBoundsException
- ifindex
is negative or greater than or equal tolength()
.length()
append
publicStringBufferappend(Objectobj)
Object
argument.
The argument is converted to a string as if by the methodString.valueOf
, and the characters of that string are then appended to this sequence.
obj
- anObject
.String.valueOf(java.lang.Object)
,append(java.lang.String)
append
publicStringBufferappend(Stringstr)
The characters of theString
argument are appended, in order, increasing the length of this sequence by the length of the argument. Ifstr
isnull
, then the four characters"null"
are appended.
Letnbe the length of this character sequence just prior to execution of theappend
method. Then the character at indexkin the new character sequence is equal to the character at indexkin the old character sequence,
ifkis less thann; otherwise, it is equal to the character at indexk-nin the argumentstr
.
str
- a string.append
publicStringBufferappend(StringBuffersb)
The characters of theStringBufferargument are appended, in order, to the contents of thisStringBuffer, increasing the length of thisStringBufferby the length of the argument. Ifsbisnull, then the four characters"null"are appended to thisStringBuffer.
Letnbe the length of the old character sequence, the one contained in theStringBufferjust prior to execution of theappendmethod. Then the character at indexkin the new character sequence is equal to the character
at indexkin the old character sequence, ifkis less thann; otherwise, it is equal to the character at indexk-nin the argumentsb
.
This method synchronizes onthis
(the destination) object but does not synchronize on the source (sb
).
sb
- theStringBufferto append.append
publicStringBufferappend(CharSequences)
CharSequence
to this sequence.
The characters of theCharSequence
argument are appended, in order, increasing the length of this sequence by the length of the argument.
The result of this method is exactly the same as if it were an invocation of this.append(s, 0, s.length());
This method synchronizes on this (the destination) object but does not synchronize on the source (s
).
Ifs
isnull
, then the four characters"null"
are appended.
append
in interfaceAppendable
s
- theCharSequence
to append.append
publicStringBufferappend(CharSequences, int start, int end)
CharSequence
to this sequence.
Characters of the arguments
, starting at indexstart
, are appended, in order, to the contents of this sequence up to the (exclusive) indexend
. The length of this sequence is increased by the value ofend - start
.
Letnbe the length of this character sequence just prior to execution of theappend
method. Then the character at indexkin this character sequence becomes equal to the character at indexkin this sequence, ifkis
less thann; otherwise, it is equal to the character at indexk+start-nin the arguments
.
Ifs
isnull
, then this method appends characters as if the s parameter was a sequence containing the four characters"null"
.
append
in interfaceAppendable
s
- the sequence to append.start
- the starting index of the subsequence to be appended.end
- the end index of the subsequence to be appended.IndexOutOfBoundsException
- ifstart
orend
are negative, orstart
is greater thanend
orend
is greater thans.length()
append
publicStringBufferappend(char[] str)
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.
The overall effect is exactly as if the argument were converted to a string by the methodString.valueOf(char[])
and the characters of that string were thenappended
to this character sequence.
str
- the characters to be appended.append
publicStringBufferappend(char[] str, int offset, int len)
char
array argument to this sequence.
Characters of thechar
arraystr
, starting at indexoffset
, are appended, in order, to the contents of this sequence. The length of this sequence increases by the value oflen
.
The overall effect is exactly as if the arguments were converted to a string by the methodString.valueOf(char[],int,int)
and the characters of that string were thenappended
to this character sequence.
str
- the characters to be appended.offset
- the index of the firstchar
to append.len
- the number ofchar
s to append.append
publicStringBufferappend(boolean b)
boolean
argument to the sequence.
The argument is converted to a string as if by the methodString.valueOf
, and the characters of that string are then appended to this sequence.
b
- aboolean
.String.valueOf(boolean)
,append(java.lang.String)
append
publicStringBufferappend(char c)
char
argument to this sequence.
The argument is appended to the contents of this sequence. The length of this sequence increases by1
.
The overall effect is exactly as if the argument were converted to a string by the methodString.valueOf(char)
and the character in that string were thenappended
to this character sequence.
append
in interfaceAppendable
c
- achar
.append
publicStringBufferappend(int i)
int
argument to this sequence.
The argument is converted to a string as if by the methodString.valueOf
, and the characters of that string are then appended to this sequence.
i
- anint
.String.valueOf(int)
,append(java.lang.String)
appendCodePoint
publicStringBufferappendCodePoint(int codePoint)
codePoint
argument to this sequence.
The argument is appended to the contents of this sequence. The length of this sequence increases byCharacter.charCount(codePoint)
.
The overall effect is exactly as if the argument were converted to achar
array by the methodCharacter.toChars(int)
and the character in that array were thenappended
to this character
sequence.
codePoint
- a Unicode code pointappend
publicStringBufferappend(long lng)
long
argument to this sequence.
The argument is converted to a string as if by the methodString.valueOf
, and the characters of that string are then appended to this sequence.
lng
- along
.String.valueOf(long)
,append(java.lang.String)
append
publicStringBufferappend(float f)
float
argument to this sequence.
The argument is converted to a string as if by the methodString.valueOf
, and the characters of that string are then appended to this string sequence.
f
- afloat
.String.valueOf(float)
,append(java.lang.String)
append
publicStringBufferappend(double d)
double
argument to this sequence.
The argument is converted to a string as if by the methodString.valueOf
, and the characters of that string are then appended to this sequence.
d
- adouble
.String.valueOf(double)
,append(java.lang.String)
delete
publicStringBufferdelete(int start, int end)
start
and extends to the character at indexend - 1
or to the end of the sequence if no such character exists. Ifstart
is
equal toend
, no changes are made.start
- The beginning index, inclusive.end
- The ending index, exclusive.StringIndexOutOfBoundsException
- ifstart
is negative, greater thanlength()
, or greater thanend
.deleteCharAt
publicStringBufferdeleteCharAt(int index)
char
at the specified position in this sequence. This sequence is shortened by onechar
.
Note: If the character at the given index is a supplementary character, this method does not remove the entire character. If correct handling of supplementary characters is required, determine the number ofchar
s to remove by callingCharacter.charCount(thisSequence.codePointAt(index))
,
wherethisSequence
is this sequence.
index
- Index ofchar
to removeStringIndexOutOfBoundsException
- if theindex
is negative or greater than or equal tolength()
.replace
publicStringBufferreplace(int start, int end,Stringstr)
String
. The substring begins at the specifiedstart
and extends to the character at indexend - 1
or to the end of the sequence
if no such character exists. First the characters in the substring are removed and then the specifiedString
is inserted atstart
. (This sequence will be lengthened to accommodate the specified String if necessary.)start
- The beginning index, inclusive.end
- The ending index, exclusive.str
- String that will replace previous contents.StringIndexOutOfBoundsException
- ifstart
is negative, greater thanlength()
, or greater thanend
.substring
publicStringsubstring(int start)
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
- ifstart
is less than zero, or greater than the length of this object.subSequence
publicCharSequencesubSequence(int start, int end)
An invocation of this method of the form
behaves in exactly the same way as the invocationsb.subSequence(begin, end)
This method is provided so that this class can implement thesb.substring(begin, end)
CharSequence
interface.subSequence
in interfaceCharSequence
start
- the start index, inclusive.end
- the end index, exclusive.IndexOutOfBoundsException
- ifstartorendare negative, ifendis greater thanlength(), or ifstartis greater thanend
substring
publicStringsubstring(int start, int end)
String
that contains a subsequence of characters currently contained in this sequence. The substring begins at the specifiedstart
and extends to the character at indexend - 1
.start
- The beginning index, inclusive.end
- The ending index, exclusive.StringIndexOutOfBoundsException
- ifstart
orend
are negative or greater thanlength()
, orstart
is greater thanend
.insert
publicStringBufferinsert(int index, char[] str, int offset, int len)
str
array argument into this sequence. The subarray begins at the specifiedoffset
and extendslen
char
s. The characters of the subarray are inserted
into this sequence at the position indicated byindex
. The length of this sequence increases bylen
char
s.index
- position at which to insert subarray.str
- Achar
array.offset
- the index of the firstchar
in subarray to be inserted.len
- the number ofchar
s in the subarray to be inserted.StringIndexOutOfBoundsException
- ifindex
is negative or greater thanlength()
, oroffset
orlen
are negative, or(offset+len)
is greater
thanstr.length
.insert
publicStringBufferinsert(int offset,Objectobj)
Object
argument into this character sequence.
The second argument is converted to a string as if by the methodString.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 to0
, and less than or equal to the length of this sequence.
offset
- the offset.obj
- anObject
.StringIndexOutOfBoundsException
- if the offset is invalid.String.valueOf(java.lang.Object)
,insert(int, java.lang.String)
,length()
insert
publicStringBufferinsert(int offset,Stringstr)
The characters of theString
argument are inserted, in order, into this sequence at the indicated offset, moving up any characters originally above that position and increasing the length of this sequence by the length of the argument. Ifstr
isnull
,
then the four characters"null"
are inserted into this sequence.
The character at indexkin the new character sequence is equal to:
- the character at indexkin the old character sequence, ifkis less than
offset
- the character at indexk
-offset
in the argumentstr
, ifkis not less thanoffset
but is less thanoffset+str.length()
- the character at indexk
-str.length()
in the old character sequence, ifkis not less thanoffset+str.length()
The offset argument must be greater than or equal to0
, and less than or equal to the length of this sequence.
offset
- the offset.str
- a string.StringIndexOutOfBoundsException
- if the offset is invalid.length()
insert
publicStringBufferinsert(int offset, char[] str)
char
array argument into this sequence.
The characters of the array argument are inserted into the contents of this sequence at the position indicated byoffset
. The length of this sequence increases by the length of the argument.
The overall effect is exactly as if the argument were converted to a string by the methodString.valueOf(char[])
and the characters of that string were theninserted
into this character sequence at the
position indicated byoffset
.
offset
- the offset.str
- a character array.StringIndexOutOfBoundsException
- if the offset is invalid.insert
publicStringBufferinsert(int dstOffset,CharSequences)
CharSequence
into this sequence.
The characters of theCharSequence
argument are inserted, in order, into this sequence at the indicated offset, moving up any characters originally above that position and increasing the length of this sequence by the length of the argument
s.
The result of this method is exactly the same as if it were an invocation of this object's insert(dstOffset, s, 0, s.length()) method.
Ifs
isnull
, then the four characters"null"
are inserted into this sequence.
dstOffset
- the offset.s
- the sequence to be insertedIndexOutOfBoundsException
- if the offset is invalid.insert
publicStringBufferinsert(int dstOffset,CharSequences, int start, int end)
CharSequence
into this sequence.
The subsequence of the arguments
specified bystart
andend
are inserted, in order, into this sequence at the specified destination offset, moving up any characters originally above that position. The length of this
sequence is increased byend - start
.
The character at indexkin this sequence becomes equal to:
- the character at indexkin this sequence, ifkis less than
dstOffset
- the character at indexk
+start-dstOffset
in the arguments
, ifkis greater than or equal todstOffset
but is less thandstOffset+end-start
- the character at indexk
-(end-start)
in this sequence, ifkis greater than or equal todstOffset+end-start
The dstOffset argument must be greater than or equal to0
, and less than or equal to the length of this sequence.
The start argument must be nonnegative, and not greater thanend
.
The end argument must be greater than or equal tostart
, and less than or equal to the length of s.
Ifs
isnull
, then this method inserts characters as if the s parameter was a sequence containing the four characters"null"
.
dstOffset
- the offset in this sequence.s
- the sequence to be inserted.start
- the starting index of the subsequence to be inserted.end
- the end index of the subsequence to be inserted.IndexOutOfBoundsException
- ifdstOffset
is negative or greater thanthis.length()
, orstart
orend
are negative, orstart
is greater
thanend
orend
is greater thans.length()
insert
publicStringBufferinsert(int offset, boolean b)
boolean
argument into this sequence.
The second argument is converted to a string as if by the methodString.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 to0
, and less than or equal to the length of this sequence.
offset
- the offset.b
- aboolean
.StringIndexOutOfBoundsException
- if the offset is invalid.String.valueOf(boolean)
,insert(int, java.lang.String)
,length()
insert
publicStringBufferinsert(int offset, char c)
char
argument into this sequence.
The second argument is inserted into the contents of this sequence at the position indicated byoffset
. The length of this sequence increases by one.
The overall effect is exactly as if the argument were converted to a string by the methodString.valueOf(char)
and the character in that string were theninserted
into this character sequence at the
position indicated byoffset
.
The offset argument must be greater than or equal to0
, and less than or equal to the length of this sequence.
offset
- the offset.c
- achar
.IndexOutOfBoundsException
- if the offset is invalid.length()
insert
publicStringBufferinsert(int offset, int i)
int
argument into this sequence.
The second argument is converted to a string as if by the methodString.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 to0
, and less than or equal to the length of this sequence.
offset
- the offset.i
- anint
.StringIndexOutOfBoundsException
- if the offset is invalid.String.valueOf(int)
,insert(int, java.lang.String)
,length()
insert
publicStringBufferinsert(int offset, long l)
long
argument into this sequence.
The second argument is converted to a string as if by the methodString.valueOf
, and the characters of that string are then inserted into this sequence at the position indicated byoffset
.
The offset argument must be greater than or equal to0
, and less than or equal to the length of this sequence.
offset
- the offset.l
- along
.StringIndexOutOfBoundsException
- if the offset is invalid.String.valueOf(long)
,insert(int, java.lang.String)
,length()
insert
publicStringBufferinsert(int offset, float f)
float
argument into this sequence.
The second argument is converted to a string as if by the methodString.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 to0
, and less than or equal to the length of this sequence.
offset
- the offset.f
- afloat
.StringIndexOutOfBoundsException
- if the offset is invalid.String.valueOf(float)
,insert(int, java.lang.String)
,length()
insert
publicStringBufferinsert(int offset, double d)
double
argument into this sequence.
The second argument is converted to a string as if by the methodString.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 to0
, and less than or equal to the length of this sequence.
offset
- the offset.d
- adouble
.StringIndexOutOfBoundsException
- if the offset is invalid.String.valueOf(double)
,insert(int, java.lang.String)
,length()
indexOf
public intindexOf(Stringstr)
isthis.toString().startsWith(str,k)
true
.str
- any string.-1
is returned.NullPointerException
- ifstr
isnull
.indexOf
public intindexOf(Stringstr, int fromIndex)
If no such value ofkexists, then -1 is returned.k >= Math.min(fromIndex, str.length()) && this.toString().startsWith(str, k)
str
- the substring for which to search.fromIndex
- the index from which to start the search.NullPointerException
- ifstr
isnull
.lastIndexOf
public intlastIndexOf(Stringstr)
this.length()
. The returned index is the largest valueksuch that
is true.this.toString().startsWith(str, k)
str
- the substring to search for.-1
is returned.NullPointerException
- ifstr
isnull
.lastIndexOf
public intlastIndexOf(Stringstr, int fromIndex)
If no such value ofkexists, then -1 is returned.k <= Math.min(fromIndex,="Math.min(fromIndex," str.length())="str.length())" &&="&&" this.toString().startsWith(str,="this.toString().startsWith(str," k)="k)"
str
- the substring to search for.fromIndex
- the index to start the search from.NullPointerException
- ifstr
isnull
.reverse
publicStringBufferreverse()
char
values) just prior to execution of thereverse
method. Then the character at indexkin the new character sequence is equal
to the character at indexn-k-1in the old character sequence.
Note that the reverse operation may result in producing surrogate pairs that were unpaired low-surrogates and high-surrogates before the operation. For example, reversing "\uDC00\uD800" produces "\uD800\uDC00" which is a valid surrogate pair.
toString
publicStringtoString()
String
object is allocated and initialized to contain the character sequence currently represented by this object. ThisString
is then returned. Subsequent changes
to this sequence do not affect the contents of theString
.toString
in interfaceCharSequence
|
Java™ Platform Standard Ed. 6 |
||||||||
PREV CLASSNEXT CLASS | FRAMESNO FRAMESAll Classes | ||||||||
SUMMARY: NESTED | FIELD |CONSTR|METHOD | DETAIL: FIELD |CONSTR|METHOD |
Submit a bug or feature
For further API reference and developer documentation, seeJava SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject tolicense terms. Also see thedocumentation redistribution policy.
相关推荐
String、StringBuilder和StringBuffer的区别 String、StringBuilder和StringBuffer的区别 String、StringBuilder和StringBuffer的区别
String ,StringBuffer与StringBuilder的区别
JAVA平台提供了两个类:String和StringBuffer,它们可以储存和操作字符串,即包含多个字符的字符数据.这个String类提供了数值不可改变的字符串.而这个StringBuffer类提供的字符串进行修改.当你知道字符数据要改变的时候...
StringBuffer练习.doc
String,StringBuffer,StringBuilder区别。几乎所有的应用开发都离不开操作字符串,理解字符串的设计和实现以及相关 工具如拼接类的使用,对写出高质量代码是非常有帮助的
StringBuffer:字符创变量 StringBuilder:字符创变量 从上面的名字可以看到,String是“字符创常量”,也就是不可改变的对象。对于这句话的理解你可能会产生这样一个疑问 ,比如这段代码:
String StringBuffer和StringBuilder 区别之源码解析 从源码角度简单对它们之间的区别进行了验证
string和Stringbuffer使用方法浅谈
StringBuffer的常用方法实例,如:append、insert等等。其中,StringBuffer与String的区别详细做了例子。
介绍了String、StringBuffer、StringBuilder的使用方法,以及理论知识
String的效率低于StringBuffer,开发时最好选用StringBuffer。
StringBuffer和String_区别 java.lang.StringBuffer线程安全的可变字符序列。一个类似于 String 的字符串缓冲区,但不能修改。虽然在任意时间点上它都包含某种特定的字符序列,但通过某些方法调用可以改变该序列的...
string和StringBuffer的区别
详解string与stringbuffer的区别,详述了String 是不可变,以及他们的再字符串连接时的效率区别!
简单的介绍了String、StringBuffer和StringBuilder的区别
对于Java中StringBuffer类的有关问题做下的思维导图,便于深化记忆,希望对你有帮助!注意:文件为.mm后缀建议下载freemind打开,免费的思维导图软件!
String及StringBuffer和StringBuilder的区别
Java中StringBuffer对象的初始化.pdf 学习资料 复习资料 教学资源