Class ParsePosition in Java

Class ParsePosition in Java

The ParsePosition class encapsulates information about the current position in a text string. A
ParsePosition can be passed to the parse() method of a Format subclass to cause parsing to
start at the index of the ParsePosition.

After an object has been parsed from the string, the index of the ParsePosition is updated to point to just after the text that was parsed. Thus, the same ParsePosition can be passed to multiple Format objects to parse through a complex string.

Perseposition objects are passed to the parse() and parseObject() methods of Format and are subclasses. The ParsePosition class represents the position in a string at which parsing should begin or at which parsing stopped.

Before calling a parse() method, we can specify the starting position of parsing bypassing the desired index to the ParsePosition() constructor, or by calling the setIndex() of an existing ParsePosition object.

When parse() returns, we can determine where parsing ended by calling getIndex(). When parsing multiple objects or values from a string, a single ParsePosition object can be used sequentially.

The Class Structure of the ObjectOutputStream is given as

public class java.text.ParsePosition extends java.lang.Object{
// Public Constructor
public ParsePosition (int index);
// Public Instance Methods
public int getIndex ();
public void setIndex (int index);

The details of the class structure are given as follows:

public ParsePosition(int index);

public ParsePosition(int index) constructor creates a ParsePosition object that is initialized to the given position.

See also  Learn Quickly about Static Keyword in Java in 5 Minutes

index – The initial position.

public int getIndex();

public int getIndex() method returns the current position of this ParsePosition.

This method returns the current position of this ParsePosition.

public void setIndex(int index);

public void setIndex(int index) method sets the current position of this ParsePosition.

index – The new position of this ParsePosition.

Apart from these ParsePosition class also has inherited methods from class- Object. They are as follows:

  • clone()
  • finalize()
  • hashCode()
  • notifyAll()
  • wait()
  • wait(long, int)
  • equals(Object)
  • getClass()
  • notify()
  • toString()
  • wait(long)

Share and Enjoy !

Leave a Reply

Your email address will not be published. Required fields are marked *