MessageFormat
public
class
MessageFormat
extends Format
| java.lang.Object | ||
| ↳ | java.text.Format | |
| ↳ | java.text.MessageFormat | |
MessageFormat provides a means to produce concatenated
messages in a language-neutral way. Use this to construct messages
displayed for end users.
MessageFormat takes a set of objects, formats them, then
inserts the formatted strings into the pattern at the appropriate places.
Note:
MessageFormat differs from the other Format
classes in that you create a MessageFormat object with one
of its constructors (not with a getInstance style factory
method). The factory methods aren't necessary because MessageFormat
itself doesn't implement locale specific behavior. Any locale specific
behavior is defined by the pattern that you provide as well as the
subformats used for inserted arguments.
Patterns and Their Interpretation
MessageFormat uses patterns of the following form:
MessageFormatPattern: String MessageFormatPattern FormatElement String FormatElement: { ArgumentIndex } { ArgumentIndex , FormatType } { ArgumentIndex , FormatType , FormatStyle } FormatType: one of number date time choice FormatStyle: short medium long full integer currency percent SubformatPattern
Within a String, a pair of single quotes can be used to
quote any arbitrary characters except single quotes. For example,
pattern string "'{0}'" represents string
"{0}", not a FormatElement. A single quote itself
must be represented by doubled single quotes '' throughout a
String. For example, pattern string "'{''}'" is
interpreted as a sequence of '{ (start of quoting and a
left curly brace), '' (a single quote), and
}' (a right curly brace and end of quoting),
not '{' and '}' (quoted left and
right curly braces): representing string "{'}",
not "{}".
A SubformatPattern is interpreted by its corresponding
subformat, and subformat-dependent pattern rules apply. For example,
pattern string "{1,number,$'#',##}"
(SubformatPattern with underline) will produce a number format
with the pound-sign quoted, with a resul