Sunday 6 July 2014

getChars (int srcBegin, int srcEnd, char[] dst, int dstBegin)

public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
int dstBegin)
Characters are copied from this sequence into the destination character array dst. The first character to be copied is at index srcBegin; the last character to be copied is at index srcEnd-1. The characters are copied into the subarray of dst starting at index dstBegin and ending at index.

public class StringBufferGetChars {
     public static void main(String args[]){
        StringBuffer str1 = new StringBuffer("Hi How are you");
        char str2[] = new char[20];
        str2[17]='e';
        str2[18] = 'n';
        str2[19] = 'd';
        
        str1.getChars(2, str1.length(), str2, 2);
        for(char i : str2){
            System.out.print(i);
        }
    }       
}

Output
   How are you   end

1. Throws IndexOutOfBoundsException - if any of the following is true:
     a. srcBegin is negative
     b. dstBegin is negative
     c. the srcBegin argument is greater than the srcEnd argument.
     d. srcEnd is greater than this.length().


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment