Spark: RDD to List
<p>I have a RDD structure </p>

<pre><code>RDD[(String, String)]
</code></pre>

<p>and I want to create 2 Lists (one for each dimension of the rdd).</p>

<p>I tried to use the rdd.foreach() and fill two ListBuffers and then convert them to Lists, but I guess each node creates its own ListBuffer because after the iteration the BufferLists are empty. How can I do it ?</p>

<p>EDIT : my approach</p>

<pre><code>val labeled = data_labeled.map { line =&gt;
  val parts = line.split(',')
  (parts(5), parts(7))
}.cache()

var testList : ListBuffer[String] = new ListBuffer()

labeled.foreach(line =&gt;
  testList += line._1
)
  val labeledList = testList.toList
  println("rdd: " + labeled.count)
  println("bufferList: " + testList.size)
  println("list: " + labeledList.size)
</code></pre>

<p>and the result is:</p>

<pre><code>rdd: 31990654
bufferList: 0
list: 0
</code></pre>