Copying an array to another array in java

In this tutorial, you will learn how to copy data from one array to another. Here, providing you an example with code and its explanation to given below.

This is a program that follows one dimensional array. In  this program, firstly we have to define a class CopyingArray. Now, we take two integer type array like: OneArray[] and TwoArray[]. The OneArray[] contains some integer type values (5,7,1,8,4,6,2) and another  is blank. After initializing this, now we get number of rows and columns by using the OneArray.length.  We use the ‘for‘ loop statement for displaying and copying ( OneArray[j] = TwoArray[j] ) the array. 

Here is the code of this program:

public class CopyingArray{
  public static void main(String[] args) {
  int OneArray[]{5,7,1,8,4,6,2};
  int TwoArray[] new int[7];
  System.out.println("Array:")
  System.out.print("[");
  for (int i=0; i< OneArray.length; i++){
      System.out.print(" "+ OneArray[i]);
  }
  System.out.print("]");
  System.out.println("\nArray 2:");
  System.out.print("[");
  for(int j=0; j< OneArray.length; j++){
      TwoArray[j= OneArray[j];
      System.out.print(" "+ TwoArray[j]);
  }
  System.out.print("]");
  }
}