Utilidades de Java Clase StringBuffer
Utilidades de Java Clase StringBuffer
Java posee gran capacidad para el manejo de cadenas dentro de sus clases String y StringBuffer. Un
objeto String representa una cadena alfanumérica de un valor constante que no puede ser cambiada
después de haber sido creada. Un objeto StringBuffer representa una cadena cuyo tamaño puede variar.
La clase StringBuffer dispone de muchos métodos para modificar el contenido de los objetos
StringBuffer. Si el contenido de una cadena va a ser modificado en un programa, habrá que sacrificar el
uso de objetos String en beneficio de StringBuffer, que aunque consumen más recursos del sistema,
permiten ese tipo de manipulaciones.
Constructor Summary
StringBuffer()
Constructs a string buffer with no characters in it and an initial capacity of 16 characters.
StringBuffer(int length)
Constructs a string buffer with no characters in it and an initial capacity specified by the
length argument.
StringBuffer(String str)
Method Summary
StringBuffer append(boolean b)
Appends the string representation of the boolean argument to the string
buffer.
StringBuffer append(char c)
Appends the string representation of the char argument to this string buffer.
StringBuffer append(char[] str)
Appends the string representation of the char array argument to this string
buffer.
StringBuffer append(char[] str, int offset, int len)
Appends the string representation of a subarray of the char array argument to
this string buffer.
StringBuffer append(double d)
Appends the string representation of the double argument to this string buffer.
StringBuffer append(float f)
Appends the string representation of the float argument to this string buffer.
StringBuffer append(int i)
Appends the string representation of the int argument to this string buffer.
StringBuffer append(long l)
Appends the string representation of the long argument to this string buffer.
StringBuffer append(Object obj)
Appends the string representation of the Object argument to this string buffer.
StringBuffer append(String str)
Appends the string to this string buffer.
StringBuffer append(StringBuffer sb)
Appends the specified StringBuffer to this StringBuffer.
int capacity()
Returns the current capacity of the String buffer.
char charAt(int index)
The specified character of the sequence currently represented by the string
buffer, as indicated by the index argument, is returned.
StringBuffer delete(int start, int end)
Removes the characters in a substring of this StringBuffer.
StringBuffer deleteCharAt(int index)
Removes the character at the specified position in this StringBuffer
(shortening the StringBuffer by one character).
void ensureCapacity(int minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified
minimum.
void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
Characters are copied from this string buffer into the destination character
array dst.
int indexOf(String str)
Returns the index within this string of the first occurrence of the specified
substring.
int indexOf(String str, 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 string
buffer.
StringBuffer insert(int offset, char c)
Inserts the string representation of the char argument into this string buffer.
StringBuffer insert(int offset, char[] str)
Inserts the string representation of the char array argument into this string
buffer.
StringBuffer insert(int index, char[] str, int offset, int len)
Inserts the string representation of a subarray of the str array argument into
this string buffer.
StringBuffer insert(int offset, double d)
Inserts the string representation of the double argument into this string buffer.
StringBuffer insert(int offset, float f)
Inserts the string representation of the float argument into this string buffer.
StringBuffer insert(int offset, int i)
Inserts the string representation of the second int argument into this string
buffer.
StringBuffer insert(int offset, long l)
Inserts the string representation of the long argument into this string buffer.
StringBuffer insert(int offset, Object obj)
Inserts the string representation of the Object argument into this string buffer.
StringBuffer insert(int offset, String str)
Inserts the string into this string buffer.
int lastIndexOf(String str)
Returns the index within this string of the rightmost occurrence of the
specified substring.
int lastIndexOf(String str, int fromIndex)
Returns the index within this string of the last occurrence of the specified
substring.
int length()
Returns the length (character count) of this string buffer.
StringBuffer replace(int start, int end, String str)
Replaces the characters in a substring of this StringBuffer with characters in
the specified String.
StringBuffer reverse()
The character sequence contained in this string buffer is replaced by the
reverse of the sequence.
void setCharAt(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.
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 StringBuffer.The substring begins at the specified index and
extends to the end of the StringBuffer.
String substring(int start, int end)
Returns a new String that contains a subsequence of characters currently
contained in this StringBuffer.
String toString()
Converts to a string representing the data in this string buffer.
Ejemplo Nro. 1
Ejemplo Nro. 2
Ejemplo Nro. 3
System.out.println("" + stringB);