ParsePosition setIndex() method in Java with Example Last Updated : 22 Jan, 2020 Comments Improve Suggest changes Like Article Like Report 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 to return. Below are the examples to illustrate the setIndex() method: Example 1: Java // Java program to demonstrate // setIndex() 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 object // using setIndex() method pos.setIndex(3); // getting the current // ParsePosition of 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 Example 2: Java // Java program to demonstrate // setIndex() 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(500); // set index for current // Parse Position object // using setIndex() method pos.setIndex(30); // getting the current // ParsePosition of 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: 30 Reference: https://docs.oracle.com/javase/9/docs/api/java/text/ParsePosition.html#setIndex-int- Comment More infoAdvertise with us Next Article ParsePosition setIndex() 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 setErrorIndex() method in Java with Example The setErrorIndex() method of java.text.ParsePosition class is used to set the index at which parse error may occur.Syntax: public void setErrorIndex(int ei) Parameter: This method takes integer ei as a parameter at which parse error may occur.Return Value: This method has nothing to return.Below ar 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 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 getIndex() method in Java with Example 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 pa 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 Like