ParsePosition (Java SE 11 & JDK 11 )
- java.lang.Object
-
- java.text.ParsePosition
-
public class ParsePosition extends Object
ParsePositionis a simple class used byFormatand its subclasses to keep track of the current position during parsing. TheparseObjectmethod in the variousFormatclasses requires aParsePositionobject as an argument.By design, as you parse through a string with different formats, you can use the same
ParsePosition, since the index parameter records the current position.- Since:
- 1.1
- See Also:
Format
-
-
Constructor Summary
Constructors Constructor Description ParsePosition(int index)Create a new ParsePosition with the given initial index.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)Overrides equals
intgetErrorIndex()Retrieve the index at which an error occurred, or -1 if the error index has not been set.
intgetIndex()Retrieve the current parse position.
inthashCode()Returns a hash code for this ParsePosition.
voidsetErrorIndex(int ei)Set the index at which a parse error occurred.
voidsetIndex(int index)Set the current parse position.
StringtoString()Return a string representation of this ParsePosition.
-
-
-
Method Detail
-
getIndex
public int getIndex()
Retrieve the current parse position. On input to a parse method, this is the index of the character at which parsing will begin; on output, it is the index of the character following the last character parsed.
- Returns:
- the current parse position
-
setIndex
public void setIndex(int index)
Set the current parse position.
- Parameters:
index- the current parse position
-
setErrorIndex
public void setErrorIndex(int ei)
Set the index at which a parse error occurred. Formatters should set this before returning an error code from their parseObject method. The default value is -1 if this is not set.
- Parameters:
ei- the index at which an error occurred- Since:
- 1.2
-
getErrorIndex
public int getErrorIndex()
Retrieve the index at which an error occurred, or -1 if the error index has not been set.
- Returns:
- the index at which an error occurred
- Since:
- 1.2
-
equals
public boolean equals(Object obj)
Overrides equals
- Overrides:
equalsin classObject- Parameters:
obj- the reference object with which to compare.- Returns:
trueif this object is the same as the obj argument;falseotherwise.- See Also:
Object.hashCode(),HashMap
-
hashCode
public int hashCode()
Returns a hash code for this ParsePosition.
- Overrides:
hashCodein classObject- Returns:
- a hash code value for this object
- See Also:
Object.equals(java.lang.Object),System.identityHashCode(java.lang.Object)
-
-
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2025, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.