title: How can I create an array of objects in Kotlin without initialization and a specific number of elements?
body: <p>I want to create an Array of objects with a specific number of elements in Kotlin, the problem is I don't now the current values for initialization of every object in the declaration, I tried:</p>
  
  <pre><code>var miArreglo = Array&lt;Medico&gt;(20, {null})
  </code></pre>
  
  <p>in Java, I have this and is exactly what I want, but i need it in Kotlin. : </p>
  
  <pre><code>Medico[] medicos = new Medico[20];
  
  for(int i = 0 ; i &lt; medicos.length; i++){
      medicos[i] = new Medico();
  
  }
  </code></pre>
  
  <p>What would be the Kotlink equivalent of the above Java code?</p>
  
  <p>Also, I tried with: </p>
  
  <pre><code>var misDoctores = arrayOfNulls&lt;medic&gt;(20)
  
  for(i in misDoctores ){
      i = medic()
  }
  </code></pre>
  
  <p>But I Android Studio show me the message: "Val cannot be reassigned"</p>