FieldPositionNameFieldPositionSynopsis
DescriptionThe FieldPosition class encapsulates information about fields in formatted output. The fields in a particular type of formatted output are identified by constants. A FieldPosition object contains its field type and the field's position within the formatted output. The field position is specified by the index of the first character in the field and the index of the last character in the field. You can use a FieldPosition object to find the position of a particular field in a formatted string. Consider the following code:
NumberFormat nf = NumberFormat.getInstance(); StringBuffer sb = new StringBuffer(); FieldPosition fp = new FieldPosition(NumberFormat.FRACTION_FIELD); nf.format(-1234.56, sb, fp); System.out.println(new String(sb)); System.out.println("FRACTION_FIELD goes from " + fp.getBeginIndex() + " to " + fp.getEndIndex() + "."); This code produces the following output:
-1,234.56 FRACTION_FIELD goes from 7 to 9. Class Summary
public class java.text.FieldPosition extends java.lang.Object { // Constructors public FieldPosition(int field); // Instance Methods public int getBeginIndex(); public int getEndIndex(); public int getField(); } ConstructorsFieldPositionpublic FieldPosition(int field)
Instance MethodsgetBeginIndexpublic int getBeginIndex()
getEndIndexpublic int getEndIndex()
getFieldpublic int getField()
Inherited Methods
See AlsoDateFormat, Format, MessageFormat, NumberFormat, ParsePosition, String |
|