我有一个MapReduce Java程序,该程序将数字列表输出为String作为最终输出。但是数量相对较长,并且占用太多空间。我想将每个数字转换为Long并存储。我该如何实现?

最佳答案

ArrayWritable可以扩展为

public class LongArrayWritable extends ArrayWritable {
    public LongArrayWritable() {
        super(Text.class);
    }

    public LongArrayWritable(LongWritable[] values) {
        super(LongWritable.class, values);
    }
}

另外,可以将String转换为LongWritable作为
String s = "123456";
new LongWritable((new Long(s)).longValue());

09-11 02:33