I want to convert String
object to IntWritable
Object in Hadoop.
any process is available for conversion.
We can convert String to Object in java with assignment operator. Each class is internally a child class of Object class. So you can assign string to Object directly. You can also convert String to Class type object using Class.
IntWritable is the Hadoop flavour of Integer, which is optimized to provide serialization in Hadoop. Java Serialization is too big or too heavy for Hadoop, hence the box classes in Hadoop implements serialization through the Interface called Writable. Writable can serialize the object in a very light way.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With