<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Explain foreach() operation in apache spark in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Explain-foreach-operation-in-apache-spark/m-p/224228#M186092</link>
    <description>&lt;P&gt;foreach() operation is an action.&lt;/P&gt;&lt;P&gt;&amp;gt; It do not return any value.&lt;BR /&gt;&amp;gt; It executes input function on each element of an RDD.&lt;/P&gt;&lt;P&gt;From :&lt;BR /&gt;&lt;A href="http://data-flair.training/blogs/rdd-transformations-actions-apis-apache-spark/#39_Foreach"&gt;http://data-flair.training/blogs/rdd-transformations-actions-apis-apache-spark/#39_Foreach&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It executes the function on each item in &lt;STRONG&gt;&lt;A href="http://data-flair.training/forums/topic/explain-foreach-operation"&gt;RDD&lt;/A&gt;&lt;/STRONG&gt;. It is good for writing database or publishing to web services. It executes parameter less function for each data items.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;val mydata = Array(1,2,3,4,5,6,7,8,9,10)
val rdd1 = sc.parallelize(mydata)
rdd1.foreach{x=&amp;gt;println(x)}

OR

rdd1.foreach{println}&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;Output:&lt;/STRONG&gt;&lt;BR /&gt;1&lt;BR /&gt;2&lt;BR /&gt;3&lt;BR /&gt;4&lt;BR /&gt;5&lt;BR /&gt;6&lt;BR /&gt;7&lt;BR /&gt;8&lt;BR /&gt;9&lt;BR /&gt;10&lt;/P&gt;</description>
    <pubDate>Mon, 21 Aug 2017 12:54:02 GMT</pubDate>
    <dc:creator>chan_di_sharma4</dc:creator>
    <dc:date>2017-08-21T12:54:02Z</dc:date>
  </channel>
</rss>

