Java Reference
In-Depth Information
CollationKeySorting(Collator collator) {
this.collator = collator;
sortedStrings = new TreeMap<CollationKey, String>();
}
void add(String str) {
sortedStrings.put(
collator.getCollationKey(str), str);
}
Iterator<String> strings() {
return sortedStrings.values().iterator();
}
}
24.6.2. Formatting and Parsing
The abstract
Format
class provides methods to format and parse objects
according to a locale.
Format
declares a
format
method that takes an ob-
ject and returns a formatted
String
, tHRowing
IllegalArgumentException
if the object is not of a type known to the formatting object.
Format
also
declares a
parseObject
method that takes a
String
and returns an ob-
ject initialized from the parsed data, throwing
ParseException
if the string
is not understood. Each of these methods is implemented as appropri-
ate for the particular kind of formatting. The package
java.text
provides
three
Format
subclasses:
•
DateFormat
was discussed in the previous section.
•
MessageFormat
helps you localize output when printing messages
that contain values from your program. Because word order var-
ies among languages, you cannot simply use a localized string
concatenated with your program's values. For example, the Eng-
lish phrase "a fantastic menu" would in French have the word or-