Example & Tutorial understanding programming in easy ways.

What stringbuffer method in java used?.

Here some important stringbuffer method in java are as given bellow.

                                    Methods                                           Description
 append(String str) Appends the string to this string buffer.
Note that the StringBuffer class has got many overloaded ‘append’ methods which can be used based on the application need.
 
 setLength(int newLength) Sets the length of this String buffer.
 reverse() The character sequence contained in this string buffer is replaced by the reverse of the sequence.
 
 toString() Converts to a string representing the data in this string buffer
 
 length() Returns the length (character count) of this string buffer.
 
 capacity() Returns the current capacity of the String buffer.
 charAt(int index) Return The specified character of the sequence currently represented by the string buffer, as indicated by the index argument, is returned.
 
 setCharAt(int index, char ch) The character at the specified index of this string buffer is set to ch
 
 insert(int offset, char c) Inserts the string representation of the char argument into this string buffer.
Note that the StringBuffer class has got many overloaded ‘insert’ methods which can be used based on the application need.
 
 delete(int start, int end) Removes the characters in a substring of this StringBuffer
 replace(int start, int end, String str) Replaces the characters in a substring of this StringBuffer with characters in the specified String.
 
enureCapacity()s Ensures that the buffer capacity is not less than a specified minimum.
insert() Overloaded.
replace() Replaces characters within a specified range in a StringBuffer object with a specified string.
hashCode (inherited from Object )

Read More →