Formatter class in java.util package helps in formatting the display numbers, string, time and date in any format you like. For e.g., we could write the amount 123456.7 as 1,23,456.7 or 123,456.7 or 123456.70 or 123.456,70 depending upon the requirement. The Formatter class helps in displaying them in required format.

Initially we will discuss various ways for creating the Formatter objects. Some of the constructors are

The most commonly used constructor is the first one and by default any data formatted using this type of Formatter, will be written to StringBuilder and using the default Locale. The output of the Formatter can be accessed using out() method.
If we want to the output to be written to our own StringBuilder then we can use the constructor 2 and 3. If we want to write to file or OutputStream we can use the other constructors. We can also pass the Locale and charset as required.