title: Spark : Creating Object RDD from List<Object> RDD
body: <p>Assume <code>Employee</code> is a Java Class.</p>
  
  <p>I have a <code>JavaRDD&lt;Employee[]&gt; arrayOfEmpList</code>, i.e, each RDD has an <code>array of employees</code>.</p>
  
  <p>Out of this, I want to create a single list of employees, something like </p>
  
  <pre><code>JavaRDD&lt;Employee&gt;
  </code></pre>
  
  <p>This is what i tried:
  Created a <code>List&lt;Employee&gt; empList  = new ArrayList&lt;Employee&gt;();</code></p>
  
  <p>then foreach RDD of Employee[]:</p>
  
  <pre><code>arrayOfEmpList.forEach(new VoidFunction&lt;Employee[]&gt;(){
  public void call(Employee[] arg0){
     empList.addAll(Arrays.asList(arg0));
     System.out.println(empList.size()); //prints correct values incrementally
  }
  });
  
  System.out.println(empList.size()); //gives 0
  </code></pre>
  
  <p>I am not able to get the size outside foreach loop.</p>
  
  <p>Is there some other way to achieve this?</p>
  
  <p>P.S: i want to have all employee records as separate RDD, so 1st employee list may contain 10 records, 2nd may contain 100 records, 3rd may contain 200 records. i want a final list of 330 records, which i can then parallelize and perform actions upon.</p>