title: Why do some elements of my array go missing ? (Kotlin)
body: <p>I don't understand why some elements go missing. My supposition is that I somehow declared my variables wrong. But if not I don't see what is wrong in the conceptualization of the code.</p>
  
  <p>I tried to create an array at the beginning of the function which is supposed to be the same at the end, but the elements are still missing.</p>
  
  <p>(Example :</p>
  
  <p>val savedArray = nameArray</p>
  
  <p>[some code where none of the two arrays are modified]</p>
  
  <p>nameArray = savedArray)</p>
  
  <hr>
  
  <pre><code>import android.support.v7.app.AppCompatActivity 
  
  import android.os.Bundle 
  
  import android.util.Log
  
  var nameArray = arrayListOf("Julia", "Maxime", "Thomas", "Dean", "Samuel")
  
  class MainActivity : AppCompatActivity() {
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
  
          Log.i("Before", "$nameArray") // ["Julia", "Maxime", "Thomas", "Dean", "Samuel"]
  
          val randomArray = choosePlayer()
  
          Log.i("After", "$nameArray") // [Maxime, Dean, Samuel] Where are Thomas and Julia ?
  
      }
  
  
      fun choosePlayer(): ArrayList&lt;String&gt; {
          val endArray = arrayListOf&lt;String&gt;()
          var editArray = nameArray
  
          val name1 = editArray.random()
  
          endArray.add(name1)
          editArray.remove(name1)
  
          val name2 = editArray.random()
  
          endArray.add(name2)
          editArray.remove(name2)
  
  
          Log.i("return value", "$endArray") // [Thomas, Julia]
          return endArray
      }
  }
  </code></pre>
  
  <p>I expect the nameArray to be full but instead two elements are always missing. I noticed that they went missing once they are removed from editArray.</p>