title: Hadoop Word count: receive the total number of words that start with the letter "c"
body: <p>Heres the Hadoop word count java map and reduce source code:</p>
  
  <p>In the map function, I've gotten to where I can output all the word that starts with the letter "c" and also the total number of times that word appears, but what I'm trying to do is just output the total number of words starting with the letter "c" but I'm stuck a little on getting the total number.Any help would be greatly appreciated, Thank you.</p>
  
  <p>Example</p>
  
  <p>My Output of what I'm getting: </p>
  
  <p>could 2</p>
  
  <p>can   3</p>
  
  <p>cat   5</p>
  
  <p>What I'm trying to get:</p>
  
  <p>c-total 10</p>
  
  <pre><code>public static class MapClass extends MapReduceBase
     implements Mapper&lt;LongWritable, Text, Text, IntWritable&gt; {
  
  private final static IntWritable one = new IntWritable(1);
  private Text word = new Text();
  
  public void map(LongWritable key, Text value,
                  OutputCollector&lt;Text, IntWritable&gt; output,
                  Reporter reporter) throws IOException {
    String line = value.toString();
    StringTokenizer itr = new StringTokenizer(line);
    while (itr.hasMoreTokens()) {
      word.set(itr.nextToken());
      if(word.toString().startsWith("c"){
      output.collect(word, one);
     }
    }
   } 
  }
  
  
  public static class Reduce extends MapReduceBase
  implements Reducer&lt;Text, IntWritable, Text, IntWritable&gt; {
  
  public void reduce(Text key, Iterator&lt;IntWritable&gt; values,
                     OutputCollector&lt;Text, IntWritable&gt; output,
                     Reporter reporter) throws IOException {
    int sum = 0;
    while (values.hasNext()) {
      sum += values.next().get(); //gets the sum of the words and add them together
    }
    output.collect(key, new IntWritable(sum)); //outputs the word and the number
    }
   }
  </code></pre>