title: Immutable Vector or List Builder in Scala
body: <p>I am running into situation where I need to extract certain entries into corresponding lists based on some condition. Here is my code</p>
  
  <pre><code>var keys = Vector[String]()
  var data = Vector[String]()
  
  for ((k, v) &lt;- myMap) {
    if (v.endsWith("abc")) { keys = keys :+ v }
    if (v.endsWith("xyz")) { data = data :+ v }
  }
  </code></pre>
  
  <p>What would be the best way to implement this logic without making <em>keys</em> and <em>data</em> as var? Is there such a thing as Immutable List builder in Scala? </p>
  
  <p>For example, ImmutableList.Builder in guava (Java) <a href="https://google.github.io/guava/releases/21.0/api/docs/com/google/common/collect/ImmutableList.Builder.html" rel="nofollow noreferrer">https://google.github.io/guava/releases/21.0/api/docs/com/google/common/collect/ImmutableList.Builder.html</a></p>