Sunday 7 June 2015

Copying Arrays

public class CopyingArrays {
        /* This example uses the arraycopy method of the System class
         * to copy part of the char array copyFrom to the char array copyTo.
         */
        public static void main(String[] args) {
                char[] copyFrom = {'d','e','c','a','f','f','e',
                        'i','n','a','t','e','d'};
                char[] copyTo = new char[7];

                System.arraycopy(copyFrom, 2, copyTo, 0, 7);
                System.out.println(new String(copyFrom) + " to " + new String(copyTo));
        }
}

No comments:

Post a Comment

Translate