You are on page 1of 1

import java.io.

IOException;
import java.util.StringTokenizer;
import
import
import
import
import

org.apache.hadoop.io.IntWritable;
org.apache.hadoop.io.LongWritable;
org.apache.hadoop.io.Text;
org.apache.hadoop.mapreduce.Mapper;
org.apache.hadoop.mapreduce.Mapper.Context;

public class AlphaMapper extends Mapper<LongWritable,Text,IntWritable,Text>


{
public void map(LongWritable key,Text value,Context con) throws IOExc
eption, InterruptedException
{
String line = value.toString();
String[] words=line.split("\\s");//splits the string based o
n spaces
//using java for each loop to print elements of string a
rray
for(String w:words)
{
int len = 0;
System.out.println("String is: "+w);
len = w.length();
value.set(w);
System.out.println("Length is: "+len);
con.write(new IntWritable(len),value);
}
}
}