Java Utility Library

Java.util.Formatter Class



Java Formatter Class

Java.util package provides a Formatter class which provides support for layout justification and alignment, common formats for numeric, string, and date/time data, and locale-specific output. Formatters are not necessarily safe for multithreaded access. Thread safety is optional and is the responsibility of users of methods in this class.

Formatted printing for the Java language is heavily inspired by C's printf. Although the format strings are similar to C, some customizations have been made to accommodate the Java language and exploit some of its features. Also, Java formatting is more strict than C's.

Class declaration

The declaration of java.util.Formatter class is:

public final class Formatter
  extends Object
    implements Closeable, Flushable

Class Constructors

S.NConstructors & Description
1. Formatter()
Constructs a new formatter.
2. Formatter(Appendable a)
Constructs a new formatter with the specified destination.
3. Formatter(Appendable a, Locale l)
Constructs a new formatter with the specified destination and locale.
4. Formatter(File file)
Constructs a new formatter with the specified file.
5. Formatter(File file, String csn)
Constructs a new formatter with the specified file and charset.
6. Formatter(File file, String csn, Locale l)
Constructs a new formatter with the specified file, charset, and locale.
7. Formatter(Locale l)
Constructs a new formatter with the specified locale.
8. Formatter(OutputStream os)
Constructs a new formatter with the specified output stream.
9. Formatter(OutputStream os, String csn)
Constructs a new formatter with the specified output stream and charset.
10. Formatter(OutputStream os, String csn, Locale l)
Constructs a new formatter with the specified output stream, charset, and locale.
11. Formatter(PrintStream ps)
Constructs a new formatter with the specified print stream.
12. Formatter(String fileName)
Constructs a new formatter with the specified file name.
13. Formatter(String fileName, String csn)
Constructs a new formatter with the specified file name and charset.
14. Formatter(String fileName, String csn, Locale l)
Constructs a new formatter with the specified file name, charset, and locale.

java.util.Formatter Methods

The java.util.Formatter class has a number of methods which are listed below:

Member Methods

S.NMethods & Description
1. String toString()
Returns the result of invoking toString() on the destination for the output.

Methods inherited

This class inherits the methods of following class:

  • java.lang.Object