/**
 * Illustrates a simple flatMap in Java to extract the words
 */
package com.oreilly.learningsparkexamples.java;

import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.FlatMapFunction;

public class BasicFlatMap {
  public static void main(String[] args) throws Exception {

		if (args.length != 2) {
      throw new Exception("Usage BasicFlatMap sparkMaster inputFile");
		}

    JavaSparkContext sc = new JavaSparkContext(
      args[0], "basicflatmap", System.getenv("SPARK_HOME"), System.getenv("JARS"));
    JavaRDD<String> rdd = sc.textFile(args[1]);
    JavaRDD<String> result = rdd.flatMap(
      new FlatMapFunction<String, String>() { public Iterable<String> call(String x) {
          return Arrays.asList(x.split(" "));
        }});
    System.out.println(StringUtils.join(result.collect(), ","));
  }
}

@@ -159,16 +159,67 @@
 l.List;%0A
+import java.util.Map;%0Aimport java.util.Map.Entry;%0A%0A
 %0Aimport 
@@ -298,16 +298,62 @@
 avaRDD;%0A
+import org.apache.spark.api.java.JavaPairRDD;%0A
 import o
@@ -846,22 +846,21 @@
 String%3E 
-result
+words
  = rdd.f
@@ -1021,68 +1021,186 @@
     
-System.out.println(StringUtils.join(result.collect(), %22,%22));
+Map%3CString, Long%3E result = words.countByValue();%0A    for (Entry%3CString, Long%3E entry: result.entrySet()) %7B%0A      System.out.println(entry.getKey() + %22:%22 + entry.getValue());%0A    %7D
 %0A  %7D

Make the basicflatmap example be a wordcount example