title: What's the best way to create a dynamically growing array in Scala?
body: <p>I wanted to add items dynamically into an array. But it seems Scala arrays and lists don't provide any methods for adding items dynamically due to the immutable nature.</p>
  
  <p>So I decided to use List data type to make use of this <strong>::</strong> method to achieve this. My code look like this</p>
  
  <pre><code>var outList = List(Nil)
  val strArray = Array("ram","sam","bam")
  
  for (str&lt;-strArray)
       outList = str :: outList
  </code></pre>
  
  <p>Though it works in some way, the problem is the new strings are pre-appended into the list. But the ideal requirement is order of the data. Yeah, I know what you are thinking, you can reverse the final result list to get the original order. But the problem is it's a huge array. And I believe it's not a solution though it solves the problem. I believe there should be a simple way to solve this...</p>
  
  <p>And my reason for hacking Scala is to learn the functional way of coding. Having <strong>var</strong> (mutable type) and populating the list on the fly seems to me is not a functional way of solving things.</p>
  
  <p>How can I do it?</p>
  
  <p>Ideally, I want to achieve something like this in Scala (below the <a href="http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29" rel="noreferrer">C#</a> code)</p>
  
  <pre><code>List&lt;int&gt; ls = new List&lt;int&gt;();    
  for (int i = 0; i &lt; 100; i++)
      ls.Add(i);
  </code></pre>