methods of string buffer

 

MethodsAction Performed
append()Used to add text at the end of the existing text.
length()The length of a StringBuffer can be found by the length( ) method
capacity()the total allocated capacity can be found by the capacity( ) method
charAt()This method returns the char value in this sequence at the specified index.
delete()Deletes a sequence of characters from the invoking object
deleteCharAt()Deletes the character at the index specified by the loc
ensureCapacity()Ensures capacity is at least equal to the given minimum.
insert()Inserts text at the specified index position
length()Returns the length of the string  
reverse()Reverse the characters within a StringBuffer object
replace()Replace one set of characters with another set inside a StringBuffer object

Methods

Description

Syntax

ensureCapacity()

It is used to increase the capacity of a StringBuffer object. The new capacity will be set to either the value we specify or twice the current capacity plus two (i.e. capacity+2), whichever is larger. Here, capacity specifies the size of the buffer.

void ensureCapacity(int capacity)

appendCodePoint(int codePoint)

This method appends the string representation of the codePoint argument to this sequence.

public StringBuffer appendCodePoint(int codePoint)

charAt(int index)

This method returns the char value in this sequence at the specified index.

public char charAt(int index)

IntStream chars()

This method returns a stream of int zero-extending the char values from this sequence.

public IntStream chars()

int codePointAt(int index)

This method returns the character (Unicode code point) at the specified index.

public int codePointAt(int index)

int codePointBefore(int index)

This method returns the character (Unicode code point) before the specified index.

public int codePointBefore(int index)

int codePointCount(int beginIndex, int endIndex)

This method returns the number of Unicode code points in the specified text range of this sequence.

public int codePointCount(int beginIndex, int endIndex)

IntStream codePoints()

This method returns a stream of code point values from this sequence.

public IntStream codePoints()

void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)

In this method, the characters are copied from this sequence into the destination character array dst.

public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)

int indexOf(String str)

This method returns the index within this string of the first occurrence of the specified substring.

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

int lastIndexOf(String str)

This method returns the index within this string of the last occurrence of the specified substring.

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

int offsetByCodePoints(int index, int codePointOffset)

This method returns the index within this sequence that is offset from the given index by codePointOffset code points.

public int offsetByCodePoints(int index, int codePointOffset)

void setCharAt(int index, char ch)

In this method, the character at the specified index is set to ch.

public void setCharAt(int index, char ch)

void setLength(int newLength)

This method sets the length of the character sequence.

public void setLength(int newLength)

CharSequence subSequence(int start, int end)

This method returns a new character sequence that is a subsequence of this sequence.

public CharSequence subSequence(int start, int end)

String substring(int start)

This method returns a new String that contains a subsequence of characters currently contained in this character sequence.

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

String toString()

This method returns a string representing the data in this sequence.

public String toString()

void trimToSize()

This method attempts to reduce storage used for the character sequence.

public void trimToSize()

Comments