substring
You can obtain a portion of a StringBuffer by calling substring( ).
The first form returns the substring that starts at startIndex and runs to the end of the invoking StringBuffer object. The second form returns the substring that starts at startIndex and runs through endIndex-1.
String substring(int start)
- Returns a new String that contains a subsequence of characters currently contained in this character sequence.
String substring(int start, int end)
- Returns a new String that contains a subsequence of characters currently contained in this sequence.
CharSequence subSequence(int start, int end)
- Returns a new character sequence that is a subsequence of this sequence.
public class Main {
public static void main(String[] argv) {
StringBuffer sb = new StringBuffer();
sb.append("java2s.com");
String sub = sb.substring(1,2);
System.out.println(sub);
System.out.println(sb.toString());
}
}
Home
Java Book
Essential Classes
Java Book
Essential Classes
StringBuffer:
- Create StringBuffer object
- append
- StringBuffer capacity()
- charAt(int index): get the char at specified index
- delete(int start, int end) and deleteCharAt(int index)
- ensureCapacity( )
- getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
- indexOf(String str)
- lastIndexOf(String str)
- StringBuffer length()
- Insert(): add data in the middle of a StringBuffer
- replace():replace a StringBuffer
- StringBuffer reverse()
- setCharAt(int index, char ch)
- setLength
- substring
- toString():Convert StringBuffer to String