How to convert a String object to an IntWritable object in Hadoop… here is a solution to the problem.
How to convert a String object to an IntWritable object in Hadoop
I want to convert a String
object to an IntWritable
object in Hadoop.
Any process can be converted.
Solution
IntWritable value = new IntWritable(Integer.parseInt(someString))
… And handle the possibility that parseInt
may throw a NumberFormatException
.
Someone asked:
How to overcome this NumberFormatException ???
If someString
does not represent an integer, an exception occurs.
What do you do?
Of course you have to capture it and deal with it! How you handle it (i.e. what you should write your application to do) depends on the context. We are unable to advise on this.
Java exceptions and exception handling are described in the Oracle Java tutorial – here