022 StringTokenizer替换掉String的操作

一:说明

1.说明

  String的操作特别消耗内存,所以可以考虑优化。

二:程序

1.程序修改

  这部分程序属于Mapper端的程序,稍微优化一下。

2.程序

 1 //Mapper
 2     public static class WordCountMapper extends Mapper<LongWritable,Text,Text,IntWritable>{
 3         private Text mapoutputkey=new Text();
 4         private static final IntWritable mapoutputvalue=new IntWritable(1);
 5         @Override
 6         protected void map(LongWritable key, Text value, Context context)throws IOException, InterruptedException {
 7             String lineValue=value.toString();
 8             StringTokenizer stringTokenizer =new StringTokenizer(lineValue);
 9             while(stringTokenizer.hasMoreTokens()){
10                 mapoutputkey.set(stringTokenizer.nextToken());
11                 context.write(mapoutputkey, mapoutputvalue);
12             }        
13         }
14         
15     }
原文地址:https://www.cnblogs.com/juncaoit/p/8214683.html