title: Difference between Spark toLocalIterator and iterator methods
body: <p>While coding the Spark programs i came across this <code>toLocalIterator()</code> method. As earlier i was using only <code>iterator()</code> method.</p>
  
  <p>If anyone has ever used this method please throw some lights.</p>
  
  <p>I came across while using <code>foreach</code> and <code>foreachPartition</code> methods in Spark program.</p>
  
  <p>Can I pass the <code>foreach</code> method result to <code>toLocalIterator</code> method or vice verse.</p>
  
  <pre><code>toLocalIterator() -&gt; foreachPartition()
  iterator() -&gt; foreach()
  </code></pre>