Name

Format

Synopsis

This abstract class is the base class for all number, date, and string formatting classes in the java.text package. It defines the key formatting and parsing methods that are implemented by all subclasses. format( ) converts an object to a string using the formatting rules encapsulated by the Format subclass and optionally appends the resulting string to an existing StringBuffer. parseObject( ) performs the reverse operation; it parses a formatted string and returns the corresponding object. Status information for these two operations is returned in FieldPosition and ParsePosition objects.

Java 1.4 defined a variant on the format( ) method. formatToCharacterIterator( ) performs the same formating operation as format( ) but returns the result as an AtttributedCharacterIterator which uses attributes to identify the various parts (such the integer part, the decimal separtator, and the fractional part of a formatted number) of the formatted string. The attribute keys are all instances of the Format.Field inner class. Each of the Format subclasses define a Field subclass that defines a set of Field constants, (such as NumberFormat.Field.DECIMAL_SEPARATOR) for use by the character iterator returned by this method. See ChoiceFormat, DateFormat, MessageFormat, and NumberFormat for subclasses that perform specific types of formatting.

java.text.Format

Figure 15-11. java.text.Format

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.