Java in a Nutshell, 5th Edition [Electronic resources]

نسخه متنی -صفحه : 1191/ 667
نمايش فراداده

FieldPositionjava.text

Java 1.1

FieldPosition objects are optionally passed to the format( ) methods of the Format class and its subclasses to return information about the start and end positions of a specific part or "field" of the formatted string. This kind of information is often useful for aligning formatted strings in columnsfor example, aligning the decimal points in a column of numbers.

The field of interest is specified when the FieldPosition( ) constructor is called. The NumberFormat and DateFormat classes define integer various constants (which end with the string _FIELD) that can be used here. In Java 1.4 and later you can also construct a FieldPosition by specifying the Format.Field object that identifies the field. (For constant Field instances, see DateFormat.Field, MessageFormat.Field and NumberFormat.Field.)

After a FieldPosition has been created and passed to a format( ) method, use getBeginIndex( ) and getEndIndex( ) methods of this class to obtain the starting and ending character positions of the desired field of the formatted string.

public class

FieldPosition { // Public Constructors

1.4 public

FieldPosition (Format.Field

attribute ); public

FieldPosition (int

field );

1.4 public

FieldPosition (Format.Field

attribute , int

fieldID ); // Public Instance Methods public int

getBeginIndex ( ); public int

getEndIndex ( ); public int

getField ( );

1.4 public Format.Field

getFieldAttribute ( );

1.2 public void

setBeginIndex (int

bi );

1.2 public void

setEndIndex (int

ei ); // Public Methods Overriding Object

1.2 public boolean

equals (Object

obj );

1.2 public int

hashCode ( );

1.2 public String

toString ( ); }

Passed To

ChoiceFormat.format( ), DateFormat.format( ), DecimalFormat.format( ), Format.format( ), MessageFormat.format( ), NumberFormat.format( ), SimpleDateFormat.format( )