The parseObject() method is a built-in method of the java.text.NumberFormat which parses a text from a string to produce a Number. The function attempts to parse text starting at a given index. When parsing occurs, the given index is set to the last character used, in case parsing fails, the given index is not changed and the error index is set to the index where the error occurs.
public final Object parseObject(String source, ParsePosition pos)
Parameters: The function accepts two parameters which are described below:
- source: specifies the string to be parsed
- pos: specifoes the ParsePosition object with index and error index information as described
Return Value: The function returns a boolean value, it returns true if numbers can be parsed as integers, else it returns false.
Exceptions: The function throws a NullPointerException if source or pos is initialized as null.
Below is the implementation of the above function:
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.