字母计数问题
//Map阶段将数据转化为输出数据类型
public class WordCountMap extends Mapper<LongWritable, Text,Text, IntWritable> {
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String word = value.toString();//转化为java对象
String[] words = word.split(" ");//拆分
// 类型 每个值 循环数组 增强for
for (String w:words){
context.write(new Text(w), new IntWritable(1));//输出
}
}
}
//Reduce 阶段将Map中输出的数据进行归纳处理
public class WordCountReduce extends Reducer<Text, IntWritable, Text,IntWritable>{
@Override
protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
Integer count = 0;//设初始个数为0
for (IntWritable v : values