Java Doc for StringBuffer.java in  » JDK-Core » lang » java » lang » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. JDK Core
2. JDK Modules
3. JDK Modules com.sun
4. JDK Modules com.sun.java
5. JDK Modules Platform
6. JDK Modules sun
7. Open Source Build
8. Open Source Graphic Library
9. Open Source IDE Eclipse
10. Open Source J2EE
11. Open Source JDBC Driver
12. Open Source Library
13. Open Source Library Database
14. Open Source Net
15. Open Source Script
16. Science
17. Security
18. Sevlet Container
19. SUN GlassFish
20. Swing Library
21. Web Services apache cxf 2.0.1
22. Web Services AXIS2
23. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java Source Code / Java Documentation » JDK Core » lang » java.lang 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.lang.AbstractStringBuilder
      java.lang.StringBuffer

StringBuffer
final public class StringBuffer extends AbstractStringBuilder implements java.io.Serializable,CharSequence(Code)
A thread-safe, mutable sequence of characters. A string buffer is like a String , but can be modified. 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 by multiple threads. The methods are synchronized where necessary so that all the operations on any particular instance behave as if they occur in some serial order that is consistent with the order of the method calls made by each of the individual threads involved.

The principal operations on a StringBuffer 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 buffer. The append method always adds these characters at the end of the buffer; the insert method adds the characters at a specified point.

For example, if z refers to a string buffer object whose current contents are "start", then the method call z.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 a StringBuffer, then sb.append(x) has the same effect as sb.insert(sb.length(), x).

Whenever an operation occurs 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 to allocate a new internal buffer array. If the internal buffer overflows, it is automatically made larger. As of release JDK 5, this class has been supplemented with an equivalent class designed for use by a single thread, StringBuilder . The StringBuilder class should generally be used in preference to this one, as it supports all of the same operations but it is faster, as it performs no synchronization.
author:
   Arthur van Hoff
version:
   1.107, 05/05/07
See Also:   java.lang.StringBuilder
See Also:   java.lang.String
since:
   JDK1.0



Field Summary
final static  longserialVersionUID
    

Constructor Summary
public  StringBuffer()
     Constructs a string buffer with no characters in it and an initial capacity of 16 characters.
public  StringBuffer(int capacity)
     Constructs a string buffer with no characters in it and the specified initial capacity.
public  StringBuffer(String str)
     Constructs a string buffer initialized to the contents of the specified string.
public  StringBuffer(CharSequence seq)
     Constructs a string buffer that contains the same characters as the specified CharSequence.

Method Summary
public synchronized  StringBufferappend(Object obj)
    
public synchronized  StringBufferappend(String str)
    
public synchronized  StringBufferappend(StringBuffer sb)
     Appends the specified StringBuffer to this sequence.

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

public  StringBufferappend(CharSequence s)
     Appends the specified CharSequence to this sequence.

The characters of the CharSequence 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).

If s is null, then the four characters "null" are appended.
Parameters:
  s - the CharSequence to append.

public synchronized  StringBufferappend(CharSequence s, int start, int end)
    
public synchronized  StringBufferappend(char str)
    
public synchronized  StringBufferappend(char str, int offset, int len)
    
public synchronized  StringBufferappend(boolean b)
    
public synchronized  StringBufferappend(char c)
    
public synchronized  StringBufferappend(int i)
    
public synchronized  StringBufferappend(long lng)
    
public synchronized  StringBufferappend(float f)
    
public synchronized  StringBufferappend(double d)
    
public synchronized  StringBufferappendCodePoint(int codePoint)
    
public synchronized  intcapacity()
    
public synchronized  charcharAt(int index)
    
public synchronized  intcodePointAt(int index)
    
public synchronized  intcodePointBefore(int index)
    
public synchronized  intcodePointCount(int beginIndex, int endIndex)
    
public synchronized  StringBufferdelete(int start, int end)
    
public synchronized  StringBufferdeleteCharAt(int index)
    
public synchronized  voidensureCapacity(int minimumCapacity)
    
public synchronized  voidgetChars(int srcBegin, int srcEnd, char dst, int dstBegin)
    
public  intindexOf(String str)
    
public synchronized  intindexOf(String str, int fromIndex)
    
public synchronized  StringBufferinsert(int index, char str, int offset, int len)
    
public synchronized  StringBufferinsert(int offset, Object obj)
    
public synchronized  StringBufferinsert(int offset, String str)
    
public synchronized  StringBufferinsert(int offset, char str)
    
public  StringBufferinsert(int dstOffset, CharSequence s)
    
public synchronized  StringBufferinsert(int dstOffset, CharSequence s, int start, int end)
    
public  StringBufferinsert(int offset, boolean b)
    
public synchronized  StringBufferinsert(int offset, char c)
    
public  StringBufferinsert(int offset, int i)
    
public  StringBufferinsert(int offset, long l)
    
public  StringBufferinsert(int offset, float f)
    
public  StringBufferinsert(int offset, double d)
    
public  intlastIndexOf(String str)
    
public synchronized  intlastIndexOf(String str, int fromIndex)
    
public synchronized  intlength()
    
public synchronized  intoffsetByCodePoints(int index, int codePointOffset)
    
public synchronized  StringBufferreplace(int start, int end, String str)
    
public synchronized  StringBufferreverse()
    
public synchronized  voidsetCharAt(int index, char ch)
    
public synchronized  voidsetLength(int newLength)
    
public synchronized  CharSequencesubSequence(int start, int end)
    
public synchronized  Stringsubstring(int start)
    
public synchronized  Stringsubstring(int start, int end)
    
public synchronized  StringtoString()
    
public synchronized  voidtrimToSize()
    

Field Detail
serialVersionUID
final static long serialVersionUID(Code)
use serialVersionUID from JDK 1.0.2 for interoperability




Constructor Detail
StringBuffer
public StringBuffer()(Code)
Constructs a string buffer with no characters in it and an initial capacity of 16 characters.



StringBuffer
public StringBuffer(int capacity)(Code)
Constructs a string buffer with no characters in it and the specified initial capacity.
Parameters:
  capacity - the initial capacity.
exception:
  NegativeArraySizeException - if the capacityargument is less than 0.



StringBuffer
public StringBuffer(String str)(Code)
Constructs a string buffer initialized to the contents of the specified string. The initial capacity of the string buffer is 16 plus the length of the string argument.
Parameters:
  str - the initial contents of the buffer.
exception:
  NullPointerException - if str is null



StringBuffer
public StringBuffer(CharSequence seq)(Code)
Constructs a string buffer that contains the same characters as the specified CharSequence. The initial capacity of the string buffer is 16 plus the length of the CharSequence argument.

If the length of the specified CharSequence is less than or equal to zero, then an empty buffer of capacity 16 is returned.
Parameters:
  seq - the sequence to copy.
exception:
  NullPointerException - if seq is null
since:
   1.5





Method Detail
append
public synchronized StringBuffer append(Object obj)(Code)

See Also:   java.lang.String.valueOf(java.lang.Object)
See Also:   StringBuffer.append(java.lang.String)



append
public synchronized StringBuffer append(String str)(Code)



append
public synchronized StringBuffer append(StringBuffer sb)(Code)
Appends the specified StringBuffer to this sequence.

The characters of the StringBuffer argument are appended, in order, to the contents of this StringBuffer, increasing the length of this StringBuffer by the length of the argument. If sb is null, then the four characters "null" are appended to this StringBuffer.

Let n be the length of the old character sequence, the one contained in the StringBuffer just prior to execution of the append method. Then the character at index k in the new character sequence is equal to the character at index k in the old character sequence, if k is less than n; otherwise, it is equal to the character at index k-n in the argument sb.

This method synchronizes on this (the destination) object but does not synchronize on the source (sb).
Parameters:
  sb - the StringBuffer to append. a reference to this object.
since:
   1.4




append
public StringBuffer append(CharSequence s)(Code)
Appends the specified CharSequence to this sequence.

The characters of the CharSequence 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).

If s is null, then the four characters "null" are appended.
Parameters:
  s - the CharSequence to append. a reference to this object.
since:
   1.5




append
public synchronized StringBuffer append(CharSequence s, int start, int end)(Code)

throws:
  IndexOutOfBoundsException -
since:
   1.5



append
public synchronized StringBuffer append(char str)(Code)



append
public synchronized StringBuffer append(char str, int offset, int len)(Code)



append
public synchronized StringBuffer append(boolean b)(Code)

See Also:   java.lang.String.valueOf(boolean)
See Also:   StringBuffer.append(java.lang.String)



append
public synchronized StringBuffer append(char c)(Code)



append
public synchronized StringBuffer append(int i)(Code)

See Also:   java.lang.String.valueOf(int)
See Also:   StringBuffer.append(java.lang.String)



append
public synchronized StringBuffer append(long lng)(Code)

See Also:   java.lang.String.valueOf(long)
See Also:   StringBuffer.append(java.lang.String)



append
public synchronized StringBuffer append(float f)(Code)

See Also:   java.lang.String.valueOf(float)
See Also:   StringBuffer.append(java.lang.String)



append
public synchronized StringBuffer append(double d)(Code)

See Also:   java.lang.String.valueOf(double)
See Also:   StringBuffer.append(java.lang.String)



appendCodePoint
public synchronized StringBuffer appendCodePoint(int codePoint)(Code)

since:
   1.5



capacity
public synchronized int capacity()(Code)



charAt
public synchronized char charAt(int index)(Code)

throws:
  IndexOutOfBoundsException -
See Also:   StringBuffer.length()



codePointAt
public synchronized int codePointAt(int index)(Code)

since:
   1.5



codePointBefore
public synchronized int codePointBefore(int index)(Code)

since:
   1.5



codePointCount
public synchronized int codePointCount(int beginIndex, int endIndex)(Code)

since:
   1.5



delete
public synchronized StringBuffer delete(int start, int end)(Code)

throws:
  StringIndexOutOfBoundsException -
since:
   1.2



deleteCharAt
public synchronized StringBuffer deleteCharAt(int index)(Code)

throws:
  StringIndexOutOfBoundsException -
since:
   1.2



ensureCapacity
public synchronized void ensureCapacity(int minimumCapacity)(Code)



getChars
public synchronized void getChars(int srcBegin, int srcEnd, char dst, int dstBegin)(Code)

throws:
  NullPointerException -
throws:
  IndexOutOfBoundsException -



indexOf
public int indexOf(String str)(Code)

throws:
  NullPointerException -
since:
   1.4



indexOf
public synchronized int indexOf(String str, int fromIndex)(Code)

throws:
  NullPointerException -
since:
   1.4



insert
public synchronized StringBuffer insert(int index, char str, int offset, int len)(Code)

throws:
  StringIndexOutOfBoundsException -
since:
   1.2



insert
public synchronized StringBuffer insert(int offset, Object obj)(Code)

throws:
  StringIndexOutOfBoundsException -
See Also:   java.lang.String.valueOf(java.lang.Object)
See Also:   StringBuffer.insert(int,java.lang.String)
See Also:   StringBuffer.length()



insert
public synchronized StringBuffer insert(int offset, String str)(Code)

throws:
  StringIndexOutOfBoundsException -
See Also:   StringBuffer.length()



insert
public synchronized StringBuffer insert(int offset, char str)(Code)

throws:
  StringIndexOutOfBoundsException -



insert
public StringBuffer insert(int dstOffset, CharSequence s)(Code)

throws:
  IndexOutOfBoundsException -
since:
   1.5



insert
public synchronized StringBuffer insert(int dstOffset, CharSequence s, int start, int end)(Code)

throws:
  IndexOutOfBoundsException -
since:
   1.5



insert
public StringBuffer insert(int offset, boolean b)(Code)

throws:
  StringIndexOutOfBoundsException -
See Also:   java.lang.String.valueOf(boolean)
See Also:   StringBuffer.insert(int,java.lang.String)
See Also:   StringBuffer.length()



insert
public synchronized StringBuffer insert(int offset, char c)(Code)

throws:
  IndexOutOfBoundsException -
See Also:   StringBuffer.length()



insert
public StringBuffer insert(int offset, int i)(Code)

throws:
  StringIndexOutOfBoundsException -
See Also:   java.lang.String.valueOf(int)
See Also:   StringBuffer.insert(int,java.lang.String)
See Also:   StringBuffer.length()



insert
public StringBuffer insert(int offset, long l)(Code)

throws:
  StringIndexOutOfBoundsException -
See Also:   java.lang.String.valueOf(long)
See Also:   StringBuffer.insert(int,java.lang.String)
See Also:   StringBuffer.length()



insert
public StringBuffer insert(int offset, float f)(Code)

throws:
  StringIndexOutOfBoundsException -
See Also:   java.lang.String.valueOf(float)
See Also:   StringBuffer.insert(int,java.lang.String)
See Also:   StringBuffer.length()



insert
public StringBuffer insert(int offset, double d)(Code)

throws:
  StringIndexOutOfBoundsException -
See Also:   java.lang.String.valueOf(double)
See Also:   StringBuffer.insert(int,java.lang.String)
See Also:   StringBuffer.length()



lastIndexOf
public int lastIndexOf(String str)(Code)

throws:
  NullPointerException -
since:
   1.4



lastIndexOf
public synchronized int lastIndexOf(String str, int fromIndex)(Code)

throws:
  NullPointerException -
since:
   1.4



length
public synchronized int length()(Code)



offsetByCodePoints
public synchronized int offsetByCodePoints(int index, int codePointOffset)(Code)

since:
   1.5



replace
public synchronized StringBuffer replace(int start, int end, String str)(Code)

throws:
  StringIndexOutOfBoundsException -
since:
   1.2



reverse
public synchronized StringBuffer reverse()(Code)

since:
   JDK1.0.2



setCharAt
public synchronized void setCharAt(int index, char ch)(Code)

throws:
  IndexOutOfBoundsException -
See Also:   StringBuffer.length()



setLength
public synchronized void setLength(int newLength)(Code)

throws:
  IndexOutOfBoundsException -
See Also:   StringBuffer.length()



subSequence
public synchronized CharSequence subSequence(int start, int end)(Code)

throws:
  IndexOutOfBoundsException -
since:
   1.4



substring
public synchronized String substring(int start)(Code)

throws:
  StringIndexOutOfBoundsException -
since:
   1.2



substring
public synchronized String substring(int start, int end)(Code)

throws:
  StringIndexOutOfBoundsException -
since:
   1.2



toString
public synchronized String toString()(Code)



trimToSize
public synchronized void trimToSize()(Code)

since:
   1.5



Fields inherited from java.lang.AbstractStringBuilder
int count(Code)(Java Doc)
char value(Code)(Java Doc)

Methods inherited from java.lang.AbstractStringBuilder
public AbstractStringBuilder append(Object obj)(Code)(Java Doc)
public AbstractStringBuilder append(String str)(Code)(Java Doc)
public AbstractStringBuilder append(StringBuffer sb)(Code)(Java Doc)
public AbstractStringBuilder append(CharSequence s)(Code)(Java Doc)
public AbstractStringBuilder append(CharSequence s, int start, int end)(Code)(Java Doc)
public AbstractStringBuilder append(char str)(Code)(Java Doc)
public AbstractStringBuilder append(char str, int offset, int len)(Code)(Java Doc)
public AbstractStringBuilder append(boolean b)(Code)(Java Doc)
public AbstractStringBuilder append(char c)(Code)(Java Doc)
public AbstractStringBuilder append(int i)(Code)(Java Doc)
public AbstractStringBuilder append(long l)(Code)(Java Doc)
public AbstractStringBuilder append(float f)(Code)(Java Doc)
public AbstractStringBuilder append(double d)(Code)(Java Doc)
public AbstractStringBuilder appendCodePoint(int codePoint)(Code)(Java Doc)
public int capacity()(Code)(Java Doc)
public char charAt(int index)(Code)(Java Doc)
public int codePointAt(int index)(Code)(Java Doc)
public int codePointBefore(int index)(Code)(Java Doc)
public int codePointCount(int beginIndex, int endIndex)(Code)(Java Doc)
public AbstractStringBuilder delete(int start, int end)(Code)(Java Doc)
public AbstractStringBuilder deleteCharAt(int index)(Code)(Java Doc)
public void ensureCapacity(int minimumCapacity)(Code)(Java Doc)
void expandCapacity(int minimumCapacity)(Code)(Java Doc)
public void getChars(int srcBegin, int srcEnd, char dst, int dstBegin)(Code)(Java Doc)
final char[] getValue()(Code)(Java Doc)
public int indexOf(String str)(Code)(Java Doc)
public int indexOf(String str, int fromIndex)(Code)(Java Doc)
public AbstractStringBuilder insert(int index, char str, int offset, int len)(Code)(Java Doc)
public AbstractStringBuilder insert(int offset, Object obj)(Code)(Java Doc)
public AbstractStringBuilder insert(int offset, String str)(Code)(Java Doc)
public AbstractStringBuilder insert(int offset, char str)(Code)(Java Doc)
public AbstractStringBuilder insert(int dstOffset, CharSequence s)(Code)(Java Doc)
public AbstractStringBuilder insert(int dstOffset, CharSequence s, int start, int end)(Code)(Java Doc)
public AbstractStringBuilder insert(int offset, boolean b)(Code)(Java Doc)
public AbstractStringBuilder insert(int offset, char c)(Code)(Java Doc)
public AbstractStringBuilder insert(int offset, int i)(Code)(Java Doc)
public AbstractStringBuilder insert(int offset, long l)(Code)(Java Doc)
public AbstractStringBuilder insert(int offset, float f)(Code)(Java Doc)
public AbstractStringBuilder insert(int offset, double d)(Code)(Java Doc)
public int lastIndexOf(String str)(Code)(Java Doc)
public int lastIndexOf(String str, int fromIndex)(Code)(Java Doc)
public int length()(Code)(Java Doc)
public int offsetByCodePoints(int index, int codePointOffset)(Code)(Java Doc)
public AbstractStringBuilder replace(int start, int end, String str)(Code)(Java Doc)
public AbstractStringBuilder reverse()(Code)(Java Doc)
public void setCharAt(int index, char ch)(Code)(Java Doc)
public void setLength(int newLength)(Code)(Java Doc)
public CharSequence subSequence(int start, int end)(Code)(Java Doc)
public String substring(int start)(Code)(Java Doc)
public String substring(int start, int end)(Code)(Java Doc)
abstract public String toString()(Code)(Java Doc)
public void trimToSize()(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

w_w__w__.j_a_va2___s_.___c___om | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.