Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Copying arrays/assigning the 'value' of the array to another.

  1. Nov 22, 2011 #1
    Code (Text):
    int[] aCopy = new int[a.length];
    for (int i = 0; i < a.length; i++)
        aCopy[i] = a[i];
    Is this the way to 'copy' an array? Basically, I want the elements inside the the array a to be copied or assigned to the array aCopy.
  2. jcsd
  3. Nov 22, 2011 #2


    Staff: Mentor

    This should work. Try it out and see.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook