StringBuilder class Methods in Java Part -II

 java.lang.StringBuilder

A mutable sequence of characters. This class provides an API compatible with StringBuffer, but with no guarantee of synchronization. This class is designed for use as a drop-in replacement for StringBuffer in places where the string buffer was being used by a single thread (as is generally the case). Where possible, it is recommended that this class be used in preference to StringBuffer as it will be faster under most implementations.


Some methods of StringBuilder class


indexOf(String str, int fromIndex)It returns the index within this string of the first occurrence of the specified substring, starting at the specified index.


insert(int offset, Object obj)It inserts the string representation of the Object argument into this character sequence. 


insert(int index, char[] str, int offset, int len) It inserts the string representation of a subarray of the array argument into this sequence. 


insert(int dstOffset, CharSequence s, int start, int end)It inserts a subsequence of the specified CharSequence into this sequence. 


lastIndexOf(String str)It returns the index within this string of the last occurrence of the specified substring.


lastIndexOf(String str, int fromIndex) It returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index.


length()It returns the length (character count).


offsetByCodePoints()It returns the index within this sequence that is offset from the given index by codePointOffset code points.


replace()It replaces the characters in a substring of this sequence with characters in the specified String. 


reverse(): The character sequence to be replaced by the reverse of the sequence.


setCharAt()The character at the specified index is set to ch.


setLength() It sets the length of the character sequence.


subSequence()It returns a new character sequence that is a subsequence of this sequence.


substring(int start)It returns a new String that contains a subsequence of characters currently contained in this character sequence.


substring(int start, int end)It returns a new String that contains a subsequence of characters currently contained in this sequence.


toString()It returns a string containing the characters in this sequence in the same order as this sequence.


trimToSize(): It attempts to reduce the storage used for the character sequence.


Some more Methods of StringBuilder class


No comments:

Post a Comment