How to convert String object to IntWritable Object in Hadoop

前端 未结 1 1701
刺人心
刺人心 2021-02-06 05:04

I want to convert String object to IntWritable Object in Hadoop. any process is available for conversion.

1条回答
  •  心在旅途
    2021-02-06 05:18

    IntWritable value = new IntWritable(Integer.parseInt(someString))
    

    ... and deal with the possibility that parseInt may throw a NumberFormatException.


    Someone asked:

    How to overcome this NumberFormatException ???

    The exception will occur if someString does not represent an integer.

    What do you do?

    You catch it and handle it of course! How you handle it (i.e. what you should code your application to do) will depending on the context. We can't advise on that.

    Java exceptions and exception handling are described in the Oracle Java Tutorials - here.

    0 讨论(0)
提交回复
热议问题