constructor that takes a Locale object with which the formatter should work. If you do not specify a locale
to the constructor, the default locale is used. The locale being used is returned by the locale method.
The destination of a Formatter object can be obtained from the out method, which returns an
Appendable object.
If writing to the destination object could throw an IOException, then the last IOException to occur (if
any) can be obtained from the ioException method.
Formatter implements Closeable and Flushable. If close or flush are invoked, then the
destination is also closed or flushed if it too implements Closeable or Flushable. Once a formatter has
been closed the only method that can be invoked is ioException; all others throw
FormatterClosedException.
The primary method of Formatter is, of course, format:
public Formatterformat(String format, Object... args)
Formats the given arguments according to the given format string and writes
them through to the destination object. The current Formatter object is
returned, allowing format invocations to be chained together.
public Formatterformat(Locale loc, String format, Object...
args)
Like the above format method, but uses the specified locale instead of the
one from the current Formatter.
The Formatter class's support of localized output is restricted to a subset of the numeric conversions (and
the date/time conversions discussed in Chapter 24). The localized numeric conversions are the integer decimal
conversion (d) and the three main floating-point conversions (e, f, g and their uppercase counterparts). For
these conversions, digit characters are taken from the active locale, and the correct sign characters, decimal
point character, and grouping character (for the , flag) are also taken from the locale. Similarly, if
zero-padding is requested the zero character is that defined by the locale. The NumberFormat class
described in Chapter 24, on page 710, provides more extensive formatting capabilities for localized numbers.
Exercise 22.1: Write a method that takes an array of floating-point values and a number indicating how many
columns to use, and prints the array contents. Try to ensure that the entries in each column line up neatly.
Assume a line is 80 characters wide.
22.2. BitSet
The BitSet class provides a way to create a bit vector that grows dynamically. In effect, a bit set is a vector
of TRue or false bits indexed from 0 to Integer.MAX_VALUE, all of them initially false. These bits
can be individually set, cleared, or retrieved. BitSet uses only sufficient storage to hold the highest index bit
that has been setany bits beyond that are deemed to be false.
Methods that take indices into the set throw IndexOutOfBoundsException if a supplied index is
negative or, where relevant, if the from index is greater than the to index.
There are two constructors for BitSet: