Array: Use arraycopy method

Question: Use arraycopy method to contents of one array to another

package Array;

/**
 * Created by aarushi on 30/4/21.
 * Q: Use the arraycopy method to copy the following array to a target
 array t :
 int[] source = {3, 4, 5};
 */
public class ArrayMethodarraycopy {

    public static void main (String [] args){
        int [] source = {3,4,5};
        int [] t= new int[source.length];
        //header of the arraycopy method in Arrays class
        //arraycopy(Object source_arr, int sourcePos, Object dest_arr, int destPos, int len)
        System.arraycopy(source, 0, t, 0, source.length);

        for (int i=0; i<t.length; i++){
            System.out.println(t[i]);
        }
    }
}

Leave a Reply

PHP JS HTML CSS BASH PYTHON CODE

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.