title: Java get an element from an array, edit it, then store it in another array, without altering the first array
body: <p>I have encountered a problem in one of my Java projects, which causes bugs.
  The problem sounds as following:</p>
  
  <p>I have two arrays. Let's name them firstArray and secondArray. Object in this case is a seperate class created by me. It works, the array can be filled with objects of that type.</p>
  
  <pre><code>Object[] firstArray= new Object[];
  Object[] secondArray = new Object[];
  </code></pre>
  
  <p>Now, when I get an element out of the first array, edit it and then copy it in the second array, the object from the first array gets altered too.</p>
  
  <pre><code>tempObj = firstArray[3];
  tempObj.modifySomething();
  secondArray[3] = tempObj;
  </code></pre>
  
  <p>Whenever I do this, the (in this case) 3rd element(actually 4th) of the first array gets the modifications. I don't want this. I want the first Array to remain intact, unmodified, and the objects I have extracted from the first array and then modified should be stored in the second so that the second array is actually the first array after some code has been run. </p>
  
  <p>P.S. Even if I get the element from the first array with Array.get(Array, index) and then modify it, the element still gets modified in the first array.</p>
  
  <p>Hopefully you understood what I wanted to say, and if so, please lend me a hand :)</p>
  
  <p>Thank you!</p>