Tuesday, 26 October 2010

StringBuffer Methods

Usually, if execution speed is a concern, you should declare a StringBuffer to be somewhat larger than you might need. This doesn't waste much space and puts fewer demands on the run-time system.
As with arrays, StringBuffer indexes start at 0 and go up to length-1. Some StringBuffer methods are:
StringBuffer Methods
StringBuffer append( char c ) append c to the end of the StringBuffer
StringBuffer append( int i ) convert i to characters, then append them to the end of the StringBuffer
StringBuffer append( long L ) convert L to characters, then append them to the end of the StringBuffer
StringBuffer append( float f ) convert f to characters, then append them to the end of the StringBuffer
StringBuffer append( double d ) convert d to characters, then append them to the end of the StringBuffer
StringBuffer append( String s ) append the characters in s to the end of the StringBuffer
int capacity() return the current capacity (capacity will grow as needed).
char charAt( int index ) get the character at index.
StringBuffer delete( int start, int end) delete characters from start to end-1
StringBuffer deleteCharAt( int index) delete the character at index
StringBuffer insert( int index, char c) insert character c at index (old characters move over to make room).
StringBuffer insert( int index, String st) insert characters from st starting at position i.
StringBuffer insert( int index, int i) convert i to characters, then insert them starting at index.
StringBuffer insert( int index, long L) convert L to characters, then insert them starting at index.
StringBuffer insert( int index, float f) convert f to characters, then insert them starting at index.
StringBuffer insert( int index, double d) convert d to characters, then insert them starting at index.
int length() return the number of characters.
StringBuffer reverse() Reverse the order of the characters.
void setCharAt( int index, char c) set the character at index to c.
String toString() return a String object containing the characters in the StringBuffer.

No comments:

Post a Comment