Classe java.lang.StringBuffer


A string buffer implements a mutable sequence of characters.

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.


	package java.lang;

		(>JDK1.0)public final
	class StringBuffer implements java.io.Serializable {

	    // Constructeurs publics
		(>JDK1.0)    public StringBuffer();
		(>JDK1.0)    public StringBuffer(int length);
		(>JDK1.0)    public StringBuffer(String str);

	    // Méthodes d'instance publiques
		(>JDK1.0)    public StringBuffer append(boolean b);
		(>JDK1.0)    public synchronized StringBuffer append(char c);
		(>JDK1.0)    public synchronized StringBuffer append(char str[]);
		(>JDK1.0)    public synchronized StringBuffer append(char str[], int offset, int len);
		(>JDK1.0)    public StringBuffer append(double d);
		(>JDK1.0)    public StringBuffer append(float f);
		(>JDK1.0)    public StringBuffer append(int i);
		(>JDK1.0)    public StringBuffer append(long l);
		(>JDK1.0)    public synchronized StringBuffer append(Object obj);
		(>JDK1.0)    public synchronized StringBuffer append(String str);
		(>JDK1.0)    public int capacity();
		(>JDK1.0)    public synchronized char charAt(int index);
		(>JDK1.0)    public synchronized void ensureCapacity(int minimumCapacity);
		(>JDK1.0)    public synchronized void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin);
		(>JDK1.0)    public StringBuffer insert(int offset, boolean b);
		(>JDK1.0)    public synchronized StringBuffer insert(int offset, char c);
		(>JDK1.0)    public synchronized StringBuffer insert(int offset, char str[]);
		(>JDK1.0)    public StringBuffer insert(int offset, double d);
		(>JDK1.0)    public StringBuffer insert(int offset, float f);
		(>JDK1.0)    public StringBuffer insert(int offset, int i);
		(>JDK1.0)    public StringBuffer insert(int offset, long l);
		(>JDK1.0)    public synchronized StringBuffer insert(int offset, Object obj);
		(>JDK1.0)    public synchronized StringBuffer insert(int offset, String str);
		(>JDK1.0)    public int length();
		(>JDK1.0)    public synchronized StringBuffer reverse();
		(>JDK1.0)    public synchronized void setCharAt(int index, char ch);
		(>JDK1.0)    public synchronized void setLength(int newLength);
		(>JDK1.0)    public String toString();
	}

Christophe Merlet
redfox@redfoxcenter.org
©Tous droits réservés
11 septembre 1998