Monday, 7 July 2014

insert (int index, char[] str, int offset, int len)

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

index - position at which to insert subarray.
str - A char array.
offset - the index of the first char in subarray to be inserted.
len - the number of chars in the subarray to be inserted.

public class StringBufferInsertCharArray {
    public static void main(String args[]){
        char c[] = {'a', 'b', 'H', 'e', 'l', 'l', 'o', ','};
        StringBuffer str = new StringBuffer("How are You");
        str.insert(0, c, 2, 6);
        System.out.println("str = " + str);
    }
}

Output
str = Hello,How are You


1. Throws StringIndexOutOfBoundsException, if index is negative or greater than length(), or offset or len are negative, or (offset+len) is greater than str.length.



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment