title: Preferred way to create a Scala list
body: <p>There are several ways to construct an immutable list in Scala (see contrived example code below). You can use a mutable ListBuffer, create a <code>var</code> list and modify it, use a <a href="http://en.wikipedia.org/wiki/Tail_call" rel="noreferrer">tail recursive</a> method, and probably others that I don't know about.</p>
  
  <p>Instinctively, I use the ListBuffer, but I don't have a good reason for doing so. Is there a preferred or idiomatic method for creating a list, or are there situations that are best for one method over another?</p>
  
  <pre><code>import scala.collection.mutable.ListBuffer
  
  // THESE are all the same as: 0 to 3 toList.
  def listTestA() ={
      var list:List[Int] = Nil
  
      for(i &lt;- 0 to 3) 
          list = list ::: List(i)
      list
  }
  
  
  def listTestB() ={
      val list = new ListBuffer[Int]()
  
      for (i &lt;- 0 to 3) 
          list += i
      list.toList
  }
  
  
  def listTestC() ={
      def _add(l:List[Int], i:Int):List[Int] = i match {
          case 3 =&gt; l ::: List(3)
          case _ =&gt; _add(l ::: List(i), i +1)
      }
      _add(Nil, 0)
  }
  </code></pre>