title: Spark Programme to Count Letters
body: <p>I write the spark program  to count the words but now I want to Count letters instead of word. Can Anyone please tell me what do I have to change in the following code:</p>
  <p>Here is the code to count words</p>
  <pre><code>public class WordCount {
  
  
  static class SplitFunction implements FlatMapFunction&lt;String, String&gt;
   {
   public Iterable&lt;String&gt; call(String s) {
      return Arrays.asList(s.split(&quot; &quot;));
    }
   }
  
  public static void main(String[] args)
  {
  
  SparkConf sparkConf = new SparkConf();
  sparkConf.setAppName(&quot;Spark WordCount example using Java&quot;);
  
  sparkConf.setMaster(&quot;local&quot;);
  JavaSparkContext sparkContext = new JavaSparkContext(sparkConf);
  
  JavaRDD&lt;String&gt; textFile = sparkContext.textFile(&quot;input.txt&quot;);
  
  JavaRDD&lt;String&gt; words = textFile.flatMap(new SplitFunction());
  
  JavaPairRDD&lt;String, Integer&gt; pairs = words.mapToPair(new PairFunction&lt;String, String, Integer&gt;() {
        public Tuple2&lt;String, Integer&gt; call(String s) {
          return new Tuple2&lt;String, Integer&gt;(s, 1);
        }
       });
   JavaPairRDD&lt;String, Integer&gt; counts = pairs.reduceByKey(
      new Function2&lt;Integer, Integer, Integer&gt;() {
        public Integer call(Integer a, Integer b) {
          return a + b;
        }
      });
  
  
  counts.saveAsTextFile(&quot;output&quot;);
  sparkContext.stop();
  sparkContext.close();
     }
   }
  </code></pre>