These classes are capable of formatting dates, numbers, and messages, parsing; searching and sorting strings; and iterating over characters, words, sentences, and line breaks. This package contains three main groups of classes and interfaces:

  • Classes for formatting and parsing
  • Classes for iteration over text
  • Classes for string collation

Formatting and Parsing

FormattingParsing

Dates and numbers are represented internally in a locale-independent way. For example, dates are kept as milliseconds since January 1, 1970, 00:00:00 UCT. When these objects are printed or displayed, they must be converted to localized strings. The locale-specific parts of a date string, such as the time zone string, are separately imported from a locale-specific resource bundle.

The format() method converts the Date object from -604656780000 milliseconds to the form "Tuesday, November 3, 1997 9:47am CST" for the U. S. English locale. The figure shows how the format() method of subclasses of Format enable instances of Number, Date, String, and other objects to be formatted to locale-specific strings.

Conversely, the parseObject() method (and parse() method in subclasses) perform the reverse operation of parsing localized strings and converting them to Number, Date, and String objects. The figure shows how the parse() method is complementary to format(). Any String formatted by format() is guaranteed to be parseable by parseObject().

Java provides six subclasses of {@link Format} for formatting dates, numbers, and messages: {@link DateFormat}, {@link SimpleDateFormat}, {@link NumberFormat}, {@link DecimalFormat}, {@link ChoiceFormat}, and {@link MessageFormat}.

String Collation

collate"CollatorRuleBasedCollator

{@link Collator} is an abstract base class. Subclasses implement specific collation strategies. One subclass, {@link RuleBasedCollator}, is currently provided and is applicable to a wide set of languages. Other subclasses may be created to handle more specialized needs. {@link CollationElementIterator} provides an iterator for stepping through each character of a locale-specific string according to the rules of a specific Collator object. {@link CollationKey} enables fast sorting of strings by representing a string as a sort key under the rules of a specific Collator object.

Word Breaks

charCharacteruser character

Locale-Sensitive Classes

Locale-Sensitive Classes
NumberFormat
DecimalFormat
DecimalFormatSymbols
MessageFormat
DateFormat
SimpleDateFormat
DateFormatSymbols
Collator
RuleBasedCollator
CollationElementIterator
CollationKey
BreakIterator
Locale-Independent Classes
Format
ChoiceFormat
FieldPosition
ParsePosition
ParseException
StringCharacterIterator
CharacterIterator

Package Specification

Related Documentation

  • {@link java.lang.Character} (for getType)
  • {@link java.util.Locale}
  • {@link java.util.Calendar}
  • {@link java.util.GregorianCalendar}
  • {@link java.util.Date}
  • {@link java.util.ResourceBundle}
  • {@link java.util.ListResourceBundle}
  • {@link java.util.PropertyResourceBundle}
  • {@link java.util.TimeZone}
  • {@link java.util.SimpleTimeZone}

Left Curve
Java SDKs and Tools
Right Curve
Left Curve
Java Resources
Right Curve
Java 8 banner (182)

Virtual Technology Summit 07.09.14 Banner

Java One 2014 RHS Banner

Duke's Choice RHS Banner