ParsePosition setErrorIndex() method in Java with Example Last Updated : 02 Feb, 2022 Comments Improve Suggest changes Like Article Like Report 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 are the examples to illustrate the setErrorIndex() method:Example 1: Java // Java program to demonstrate // setErrorIndex() 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 // using setErrorIndex() method pos.setErrorIndex(3); // getting the current // ParsePosition of int i = pos.getErrorIndex(); // display result System.out.println( "index at which error occurred: " + Integer.toString(i)); } catch (ClassCastException e) { System.out.println(e); } } } Output: index at which error occurred: 3 Example 2: Java // Java program to demonstrate // setErrorIndex() 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 the parsing error // using setErrorIndex() method pos.setErrorIndex(3000); // getting the current // ParsePosition of int i = pos.getErrorIndex(); // display result System.out.println( "index at which error occurred: " + Integer.toString(i)); } catch (ClassCastException e) { System.out.println(e); } } } Output: index at which error occurred: 3000 Reference: https://docs.oracle.com/javase/9/docs/api/java/text/ParsePosition.html#setErrorIndex-int- Comment More infoAdvertise with us Next Article ParsePosition setErrorIndex() 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 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 PrintWriter setError() method in Java with Examples The setError() method of PrintWriter Class in Java is used to set the error state of this PrintWriter instance. This method is used as an indicator to indicate that an error has occurred in the stream. It is protected and hence needs to be implemented by deriving the PrintWriter class to use it. Syn 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 PrintStream setError() method in Java with Examples The setError() method of PrintStream Class in Java is used to set the error state of this PrintStream instance. This method is used as an indicator to indicate that an error has occurred in the stream. It is protected and hence needs to be implemented by deriving the PrintStream class to use it. Syn 2 min read Like