title: Get distinct items from rows of comma separated strings in Spark 2.0
body: <p>I am using Spark 2.0 to analyze a data set. One column contains string data like this:</p>
  
  <pre><code>A,C
  A,B
  A
  B
  B,C
  </code></pre>
  
  <p>I want to get a JavaRDD with all distinct items that appears in the column, something like this:</p>
  
  <pre><code>A
  B
  C 
  </code></pre>
  
  <p>How can this be done efficiently in spark? I am using Spark with Java, but Scala examples or pointers would be useful. </p>
  
  <p>Edit: 
  I have tried using flatMap, but my implementation is very slow. </p>
  
  <pre><code>JavaRDD&lt;String&gt; d = dataset.flatMap(s -&gt; Arrays.asList(s.split(",")).iterator())
  </code></pre>