title: Java: How to make a copy of an array of object?
body: <p>Right now, I have an array of Point objects and I want to make a <em>COPY</em> of that array.</p>
  
  <p>I have tried following ways:</p>
  
  <p>1) <code>Point[] temp = mypointarray;</code></p>
  
  <p>2) <code>Point[] temp = (Point[]) mypointarray.clone();</code></p>
  
  <p>3) </p>
  
  <pre><code>Point[] temp = new Point[mypointarray.length];
  System.arraycopy(mypointarray, 0, temp, 0, mypointarray.length);
  </code></pre>
  
  <p>But all of those ways turn out to be that only a reference of mypointarray is created for temp, not a copy.</p>
  
  <p>For example, when I changed the x coordinate of mypointarray[0] to 1 (the original value is 0), the x coordinate of temp[0] is changed to 1 too (I swear I didn't touch temp).</p>
  
  <p>So is there any ways to make an copy of Point array?</p>
  
  <p>Thanks</p>