Sunday, 6 July 2014

delete (int start, int end)

public synchronized StringBuffer delete(int start, int end)
Removes the characters in a substring of this sequence. The substring begins at the specified start and extends to the character at index end – 1.

public class StringBufferDelete {
    public static void main(String args[]){
        StringBuffer str1 = new StringBuffer("Hi How are you");
        
        System.out.println("str1 before calling delete method");
        System.out.println(str1);
        
        System.out.println("str1 after calling delete method");
        str1.delete(2,10);
        System.out.println(str1);
    }
}

Output
str1 before calling delete method
Hi How are you
str1 after calling delete method
Hi you

1. Throws StringIndexOutOfBoundsException - if start is negative, greater than length(), or greater than end.



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment