All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----java.lang.StringBuffer
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.
 String buffers are used by the compiler to implement the binary 
 string concatenation operator +. For example, the code:
 
     x = "a" + 4 + "c"
 is compiled to the equivalent of:
     x = new StringBuffer().append("a").append(4).append("c")
                           .toString()
 
 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". 
 
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.
 
 StringBuffer()
	StringBuffer()
   StringBuffer(int)
	StringBuffer(int)
  length argument.
   StringBuffer(String)
	StringBuffer(String)
   
 append(boolean)
	append(boolean)
  boolean 
 argument to the string buffer.
   append(char)
	append(char)
  char 
 argument to this string buffer.
   append(char[])
	append(char[])
  char array 
 argument to this string buffer.
   append(char[], int, int)
	append(char[], int, int)
  char array argument to this string buffer.
   append(double)
	append(double)
  double 
 argument to this string buffer.
   append(float)
	append(float)
  float 
 argument to this string buffer.
   append(int)
	append(int)
  int 
 argument to this string buffer.
   append(long)
	append(long)
  long 
 argument to this string buffer.
   append(Object)
	append(Object)
  Object 
 argument to this string buffer.
   append(String)
	append(String)
   capacity()
	capacity()
   charAt(int)
	charAt(int)
   ensureCapacity(int)
	ensureCapacity(int)
   getChars(int, int, char[], int)
	getChars(int, int, char[], int)
  dst.
   insert(int, boolean)
	insert(int, boolean)
  boolean 
 argument into this string buffer.
   insert(int, char)
	insert(int, char)
  char 
 argument into this string buffer.
   insert(int, char[])
	insert(int, char[])
  char array 
 argument into this string buffer.
   insert(int, double)
	insert(int, double)
  double 
 argument into this string buffer.
   insert(int, float)
	insert(int, float)
  float 
 argument into this string buffer.
   insert(int, int)
	insert(int, int)
  int 
 argument into this string buffer.
   insert(int, long)
	insert(int, long)
  long 
 argument into this string buffer.
   insert(int, Object)
	insert(int, Object)
  Object 
 argument into this string buffer.
   insert(int, String)
	insert(int, String)
   length()
	length()
   reverse()
	reverse()
   setCharAt(int, char)
	setCharAt(int, char)
  ch.
   setLength(int)
	setLength(int)
   toString()
	toString()
   
 StringBuffer
StringBuffer
public StringBuffer()
 StringBuffer
StringBuffer
public StringBuffer(int length)
length argument.
length
               argument is less than 0.
   StringBuffer
StringBuffer
public StringBuffer(String str)
16 plus the length 
 of the string argument.
 
 length
length
public int length()
 capacity
capacity
public int capacity()
 ensureCapacity
ensureCapacity
public synchronized void ensureCapacity(int minimumCapacity)
minimumCapacity argument. 
 2. 
 minimumCapacity argument is nonpositive, this
 method takes no action and simply returns.
 setLength
setLength
public synchronized void setLength(int newLength)
newLength argument is less than the current 
 length of the string buffer, the string buffer is truncated to 
 contain exactly the number of characters given by the 
 newLength argument. 
 
 If the newLength argument is greater than or equal 
 to the current length, sufficient null characters 
 ('\u0000') are appended to the string buffer so that 
 length becomes the newLength argument. 
 
 The newLength argument must be greater than or equal 
 to 0.
newLength argument is invalid.
     charAt
charAt
public synchronized char charAt(int index)
 The first character of a string buffer is at index 
 0, the next at index 1, and so on, for 
 array indexing. 
 
 The index argument must be greater than or equal to 
 0, and less than the length of this string buffer.
 getChars
getChars
 public synchronized void getChars(int srcBegin,
                                   int srcEnd,
                                   char dst[],
                                   int dstBegin)
dst. The first character to 
 be copied is at index srcBegin; the last character to 
 be copied is at index srcEnd-1. The total number of 
 characters to be copied is srcEnd-srcBegin. The 
 characters are copied into the subarray of dst starting 
 at index dstBegin and ending at index:
 
     dstbegin + (srcEnd-srcBegin) - 1
 
dst.
     setCharAt
setCharAt
 public synchronized void setCharAt(int index,
                                    char ch)
ch. 
 
 The offset argument must be greater than or equal to 
 0, and less than the length of this string buffer.
 append
append
public synchronized StringBuffer append(Object obj)
Object 
 argument to this string buffer. 
 
 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 string buffer.
 append
append
public synchronized StringBuffer append(String str)
 The characters of the String argument are appended, in 
 order, to the contents of this string buffer, increasing the 
 length of this string buffer by the length of the argument.
 append
append
public synchronized StringBuffer append(char str[])
char array 
 argument to this string buffer. 
 The characters of the array argument are appended, in order, to the contents of this string buffer. The length of this string buffer increases by the length of the argument.
 append
append
public synchronized StringBuffer append(char str[], int offset, int len)
char array argument to this string buffer. 
 
 Characters of the character array str, starting at 
 index offset, are appended, in order, to the contents 
 of this string buffer. The length of this string buffer increases 
 by the value of len.
 append
append
public StringBuffer append(boolean b)
boolean 
 argument to the string buffer. 
 
 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 string buffer.
 append
append
public synchronized StringBuffer append(char c)
char 
 argument to this string buffer. 
 
 The argument is appended to the contents of this string buffer. 
 The length of this string buffer increases by 1.
char.
     append
append
public StringBuffer append(int i)
int 
 argument to this string buffer. 
 
 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 string buffer.
 append
append
public StringBuffer append(long l)
long 
 argument to this string buffer. 
 
 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 string buffer.
 append
append
public StringBuffer append(float f)
float 
 argument to this string buffer. 
 
 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 string buffer.
 append
append
public StringBuffer append(double d)
double 
 argument to this string buffer. 
 
 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 string buffer.
 insert
insert
public synchronized StringBuffer insert(int offset, Object obj)
Object 
 argument into this string buffer. 
 
 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 string buffer 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 
 string buffer.
Object.
     insert
insert
public synchronized StringBuffer insert(int offset, String str)
 The characters of the String argument are inserted, in 
 order, into this string buffer at the indicated offset. The length 
 of this string buffer is increased by the length of the argument. 
 
 The offset argument must be greater than or equal to 
 0, and less than or equal to the length of this 
 string buffer.
 insert
insert
public synchronized StringBuffer insert(int offset, char str[])
char array 
 argument into this string buffer. 
 
 The characters of the array argument are inserted into the 
 contents of this string buffer at the position indicated by 
 offset. The length of this string buffer increases by 
 the length of the argument.
 insert
insert
public StringBuffer insert(int offset, boolean b)
boolean 
 argument into this string buffer. 
 
 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 string buffer 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 
 string buffer.
boolean.
     insert
insert
public synchronized StringBuffer insert(int offset, char c)
char 
 argument into this string buffer. 
 
 The second argument is inserted into the contents of this string 
 buffer at the position indicated by offset. The length 
 of this string buffer increases by one. 
 
 The offset argument must be greater than or equal to 
 0, and less than or equal to the length of this 
 string buffer.
char.
     insert
insert
public StringBuffer insert(int offset, int i)
int 
 argument into this string buffer. 
 
 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 string buffer 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 
 string buffer.
int.
     insert
insert
public StringBuffer insert(int offset, long l)
long 
 argument into this string buffer. 
 
 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 string buffer 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 
 string buffer.
long.
     insert
insert
public StringBuffer insert(int offset, float f)
float 
 argument into this string buffer. 
 
 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 string buffer 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 
 string buffer.
float.
     insert
insert
public StringBuffer insert(int offset, double d)
double 
 argument into this string buffer. 
 
 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 string buffer 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 
 string buffer.
double.
     reverse
reverse
public synchronized StringBuffer reverse()
 toString
toString
public String toString()
String object is allocated and initialized to 
 contain the character sequence currently represented by this 
 string buffer. This String is then returned. Subsequent 
 changes to the string buffer do not affect the contents of the 
 String.
All Packages Class Hierarchy This Package Previous Next Index