Menu
Topics Index
...
`


More Utility Classes > Formatter >
Siva Nookala - 03 Mar 2017
The most important method on the Formatter class is format. Using this method, we can format the data to our requirements.

This table shows various methods on the Formatter class.
MethodDescription
Formatter format(String fmtString, Object... args)This is the main method which we need to use to format various objects like Strings, numbers, date and time to the required format.
Formatter format(Locale loc, String fmtString, Object... args)Same as the previous format method, but additionally we can pass the Locale to do the formatting depending upon the Locale.
void close()closes the Formatter and releases any underlying resources. Should be called after you are done with using the Formatter.
void flush()Writes the formatted data into the underlying resource. If we created the Formatter using the File, then this method will forcefully write all the content into the File.
IOException ioException()Returns any underlying exception, if it happens during the formatting. If no exception occurs it return null.
Locale locale()Returns the Locale used for formatting.
Appendable out()Returns the reference to the underlying object which could be StringBuilder or any other OutputStream.
String toString()Returns the formatted content as String. After we have formatted the data, we can use this method to easily print the output.
In Java Formatter , we will understand how to use the Formatter using an example.

0
Wrong
Score more than 2 points

© meritcampus 2016 - 2017

All Rights Reserved.