public class StringBufferOperation{
public static void main(String[] args){
StringBuffer strBuf1 = new StringBuffer("Prashant");
System.out.println("strBuf " + strBuf1); //printing Prashant
System.out.println("strBuf " + strBuf1.capacity());//16(default capacity) + 8 characters of 'Prashant' ie.24
System.out.println("strBuf " + strBuf1.length());//showing length of string 'Prashant' ie. 8
System.out.println("strBuf " + strBuf1.charAt(5));//showing character at position 5 ie. 0-5 ie.'a' in string 'Prashant'
System.out.println("strBuf " + strBuf1.toString());//converts to a string representing the data in this string buffer.
strBuf1.delete(3,5);
System.out.println("strBuf " + strBuf1);//Printing Praant.
strBuf1.insert(2,'c');
System.out.println("strBuf " + strBuf1);// Printing Prashant as Prcashant
strBuf1.setCharAt(0,'r');
System.out.println("strBuf" +strBuf1);//It will Printing rrcshant.
//replace(int start, int end, String str)
// reverse()
//append(String str)
//setLength(int newLength)
}
}
Saturday, February 20, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment