ParsePosition getIndex() method in Java with Example Last Updated : 22 Jan, 2020 Comments Improve Suggest changes Like Article Like Report The getIndex() method of java.text.ParsePosition class is used to retrieve the current parse position of this ParsePositon object . Syntax: public int getIndex() Parameter: This method does not accepts any argument as parameter. Return Value: This method returns the current parse position of this parse position object. Below are the examples to illustrate the getIndex() method: Example 1: Java // Java program to demonstrate // getIndex() method import java.text.*; import java.util.*; import java.io.*; public class GFG { public static void main(String[] argv) { try { // Creating and initializing // new ParsePosition Object ParsePosition pos = new ParsePosition(1); // set index for the parsing error pos.setErrorIndex(3); // getting the current // ParsePosition of // using getIndex() method int i = pos.getIndex(); // display result System.out.println( "current parse position: " + Integer.toString(i)); } catch (ClassCastException e) { System.out.println(e); } } } Output: current parse position: 1 Example 2: Java // Java program to demonstrate // getIndex() method import java.text.*; import java.util.*; import java.io.*; public class GFG { public static void main(String[] argv) { try { // Creating and initializing // new ParsePosition Object ParsePosition pos = new ParsePosition(1); // set index for current // Parse Position pos.setIndex(3); // getting the current // ParsePosition of // using getIndex() method int i = pos.getIndex(); // display result System.out.println( "current parse position: " + Integer.toString(i)); } catch (ClassCastException e) { System.out.println(e); } } } Output: current parse position: 3 Reference: https://docs.oracle.com/javase/9/docs/api/java/text/ParsePosition.html#getIndex-- Comment More infoAdvertise with us Next Article ParsePosition getIndex() method in Java with Example R rohitprasad3 Follow Improve Article Tags : Java Java-Functions Java-text package Java-ParsePosition Practice Tags : Java Similar Reads ParsePosition getErrorIndex() method in Java with Example The getErrorIndex() method of java.text.ParsePosition class is used to retrieve the index at which parse error may occur. Syntax: public int getErrorIndex() Parameter: This method does not accepts any argument as a parameter. Return Value: This method returns the index at which parse error may occur 2 min read ParsePosition hashCode() method in Java with Example The hashCode() method of java.text.ParsePosition class is used to retrieve the hash code for the current parse position object. Syntax: public int hashCode() Parameter: This method does not accepts any argument as parameter. Return Value: This method returns the hash code for the current parse posit 2 min read ParsePosition equals() method in Java with Example The equals() method of java.text.ParsePosition class is used to check if both the ParsePosition objects are same or not. Syntax: public boolean equals(Object obj) Parameter: This method takes ParsePosition objects which will be compared with the current ParsePosition object. Return Value: if both th 2 min read ParsePosition setIndex() method in Java with Example The setIndex() method of java.text.ParsePosition class is used to set the current parse position of this ParsePositon object . Syntax: public void setIndex(int index) Parameter: This method takes integer index at which current parse position is going to be set. Return Value: This method has nothing 2 min read ParsePosition toString() method in Java with Example The toString() method of java.text.ParsePosition class is used to retrieve the parse position object represented in the form of string.Syntax: public String toString() Parameter: This method does not accepts any argument as parameter.Return Value: This method returns the parse position object repres 2 min read Like