Code example for StringTokenizer

Methods: hasMoreTokens, nextToken

0
public class TransformVMap extends MapReduceBase implements Mapper<LongWritable, Text, Text, Text>
{ 
	public void map(LongWritable key, Text value, OutputCollector<Text, Text> output, Reporter reporter) throws IOException 
	{ 
		String line = value.toString();
		StringTokenizer tokenizer = new StringTokenizer(line,", ");
		 
		String type = null;
		if (tokenizer.hasMoreTokens())
		{ 
			type = tokenizer.nextToken();
		} 
		 
		if (type.contains("V"))
		{ 
			String dIndex = tokenizer.nextToken();
            String movieId = tokenizer.nextToken();
            String val = tokenizer.nextToken();
             
            output.collect(new Text(movieId), new Text(dIndex +", " + val));
		} 
	} 
}