Java 中如何对 Iterator values 实现两次遍历

Just like this!!!!!!!!!!!!!!!!

===============================================================

 public static class Reduce extends MapReduceBase implements
  Reducer<IntWritable, Text, NullWritable, Text> {
 
    @Override
    public void reduce(IntWritable dummy, Iterator<Text> values,
        OutputCollector<NullWritable, Text> output, Reporter reporter)
            throws IOException { 
    	
    	List<Text> cache = new ArrayList<Text>();

    	// first loop and caching   
    	while (values.hasNext()) {
    		 
    	   cache.add(new Text(values.next()));
    		  
    	}
    	 
    	// second loop 
    	for(Text p:cache) {
    	 
           output.collect(NullWritable.get(), p);
       	 
    	} 
      
    }
  }  


你可能感兴趣的:(java,mapreduce)