Copying Array Elements in Java Programming

This video tutorial made by LearningLad explains how to copy array elements in detail with example.

You will learn how to use a loop to copy the array elements individually, what happens if we change the array elements values in detail with example.




Source code for this video tutorial

package learningJava;

public class Mango {

public static void main(String[] args) {

 int marks[] = {22,44,55,99,88};
 int markscopy[] = new int[5];
 
/* for(int counter = 0; counter < marks.length; counter++){
  markscopy[counter] = marks[counter];
 }
*/
 
 System.arraycopy(marks, 1, markscopy, 1, marks.length-1);
 
 //marks[2] = 200;
 
 System.out.println("The marks array");
 for(int counter = 0; counter < marks.length; counter++){
  System.out.println(marks[counter]);
 }
 
 System.out.println("\nThe markscopy array");
 
 for(int counter = 0; counter < markscopy.length; counter++){
  System.out.println(markscopy[counter]);
 }

}

}