Class Buffer


  extended by Object
      extended by Buffer

public class Buffer
extends Object

A string buffer implements a 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.

The elements in the buffer can be accessed with the operators get and set using brackets.

See Also:
Operators

Constructor Summary
Buffer()
          Constructs a string buffer with no characters in it and an initial capacity of 16 characters.
Buffer(int capacity)
          Constructs a string buffer with no characters in it and an initial capacity specified by the capacity argument.
 
Method Summary
 Buffer append(boolean b)
          Appends the string representation of the boolean argument to the string buffer.
 Buffer append(char c)
          Appends the specified char argument to this string buffer.
 Buffer append(int i)
          Appends the string representation of the int argument to this string buffer.
 Buffer append(long l)
          Appends the string representation of the long argument to this string buffer.
 Buffer append(Object obj)
          Appends the string representation of the Object argument to this string buffer.
 Buffer delete(int start, int end)
          Removes the characters in a substring of this Buffer.
 Buffer insert(int offset, boolean b)
          Inserts the string representation of the boolean argument into this string buffer.
 Buffer insert(int offset, char c)
          Inserts the second char argument into this string buffer.
 Buffer insert(int offset, int i)
          Inserts the string representation of the second int argument into this string buffer.
 Buffer insert(int offset, long l)
          Inserts the string representation of the long argument into this string buffer.
 Buffer insert(int offset, Object obj)
          Inserts the string representation of the Object argument into this string buffer.
 int length()
          Returns the length (character count) of this string buffer.
 char operator_get(int index)
          The specified character of the sequence currently represented by the string buffer, as indicated by the index argument, is returned.
 char operator_set(int index, char ch)
          The character at the specified index of this string buffer is set to ch.
 void setLength(int newLength)
          Sets the length of this String buffer.
 
Methods inherited from class Object
toString, equals, hashCode
 
Methods inherited from
equals, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Buffer

public Buffer()
Constructs a string buffer with no characters in it and an initial capacity of 16 characters.


Buffer

public Buffer(int capacity)
Constructs a string buffer with no characters in it and an initial capacity specified by the capacity argument.

Parameters:
capacity - the initial capacity.
Method Detail

append

public Buffer append(boolean b)
Appends the string representation of the boolean argument to the string buffer.

Parameters:
b - a boolean.
Returns:
a reference to this Buffer.

append

public Buffer append(int i)
Appends the string representation of the int argument to this string buffer.

Parameters:
i - an int.
Returns:
a reference to this Buffer object.

append

public Buffer append(char c)
Appends the specified char argument to this string buffer.

Parameters:
c - an char.
Returns:
a reference to this Buffer object.

append

public Buffer append(long l)
Appends the string representation of the long argument to this string buffer.

Parameters:
l - a long.
Returns:
a reference to this Buffer object.

append

public Buffer append(Object obj)
Appends the string representation of the Object argument to this string buffer.

Parameters:
obj - an Object.
Returns:
a reference to this Buffer object.

insert

public Buffer insert(int offset,
                     boolean b)
Inserts the string representation of the boolean argument into this string buffer.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this string buffer.

Parameters:
offset - the offset.
b - a boolean.
Returns:
a reference to this Buffer object.

insert

public Buffer insert(int offset,
                     int i)
Inserts the string representation of the second int argument into this string buffer.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this string buffer.

Parameters:
offset - the offset.
i - an int.
Returns:
a reference to this Buffer object.

insert

public Buffer insert(int offset,
                     char c)
Inserts the second char argument into this string buffer.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this string buffer.

Parameters:
offset - the offset.
c - an char.
Returns:
a reference to this Buffer object.

insert

public Buffer insert(int offset,
                     long l)
Inserts the string representation of the long argument into this string buffer.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this string buffer.

Parameters:
offset - the offset.
l - a long.
Returns:
a reference to this Buffer object.

insert

public Buffer insert(int offset,
                     Object obj)
Inserts the string representation of the Object argument into this string buffer.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this string buffer.

Parameters:
offset - the offset.
obj - an Object.
Returns:
a reference to this Buffer object.

operator_get

public char operator_get(int index)
The specified character of the sequence currently represented by the string buffer, as indicated by the index argument, is returned. 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.

Parameters:
index - the index of the desired character.
Returns:
the character at the specified index of this string buffer.
See Also:
length(), get

operator_set

public char operator_set(int index,
                         char ch)
The character at the specified index of this string buffer is set to ch. The string buffer 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 offset argument must be greater than or equal to 0, and less than the length of this string buffer.

Parameters:
index - the index of the character to modify.
ch - the new character.
See Also:
length(), set

delete

public Buffer delete(int start,
                     int end)
Removes the characters in a substring of this Buffer. The substring begins at the specified start and extends to the character at index end - 1 or to the end of the Buffer if no such character exists. If start is equal to end, no changes are made.

Parameters:
start - The beginning index, inclusive.
end - The ending index, exclusive.
Returns:
This string buffer.

length

public int length()
Returns the length (character count) of this string buffer.

Returns:
the length of the sequence of characters currently represented by this string buffer.

setLength

public void setLength(int newLength)
Sets the length of this String buffer. This string buffer is altered to represent a new character sequence whose length is specified by the argument. For every nonnegative index k less than newLength, the character at index k in the new character sequence is the same as the character at index k in the old sequence if k is less than the length of the old character sequence; otherwise, it is the null character ''. In other words, if the 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.

Parameters:
newLength - the new length of the buffer.
See Also:
length()