title: Combining RDD's in a loop
body: <p>Here is my scenario : </p>
  
  <p>I have a list of RDD called fileNamesList .</p>
  
  <pre><code>List&lt;JavaRDD&lt;Tuple2&lt;String, String&gt;&gt;&gt; fileNamesList = new ArrayList&lt;JavaRDD&lt;Tuple2&lt;String, String&gt;&gt;&gt;();
  
  fileNamesList.add(newRDD); //adding RDD's to list
  </code></pre>
  
  <p>I am adding multiple newRDD's into the list, this is inside a loop.So the list grows up to 10 maximum .</p>
  
  <p>I want to combine(union) all the RDD's inside the list <code>fileNamesList</code>  . Is it possible to do like below ;</p>
  
  <pre><code>JavaPairRDD&lt;String, String&gt; finalFileNames ;
  
      for (int j = 0; j &lt; IdList.size()-1; j++) {
  
  
          finalFileNames = JavaPairRDD.fromJavaRDD(fileNamesList.get(j)).
                  union(JavaPairRDD.fromJavaRDD(fileNamesList.get(j + 1)));
      }
  </code></pre>
  
  <p>Or what is the other option that I could use .</p>