Formatting a String in Java feels very similar. The format method of the Formatter is exposed via a static method from the String class. The flag here is made up of two characters. The second character depends on what part of Calendar is to be displayed. In our example, the first format specifiers tm, indicates month formatted as two digits, te indicates the day of the month and tY indicated Year formatted as four digits. The required conversion is a character or String indicating content to be inserted in the output. java code beautifier Note that you can find all the details in the. As we noticed in the above examples, conversion part is required in all format specifiers, and it can be divided into several categories. General Used for any argument type. Character Used for the basic types which represent Unicode characters: char, Character, byte, Byte, short, and Short. This conversion can also be used for the types int and Integer when the Character. Numeric — Integral These are used for Java java code beautifier types: byte, Byte, short, Short, int and Integer, long, Long, and BigInteger. Flags Flags, in general, are used to format the output. Whereas in case of date and time, they are used to specify which part of the date is to be displayed, as we saw in the Section 4 example. A number of flags are available, a list of which can be found in the documentation. Precision For general conversions, precision is just the maximum number of characters to be written to the output. Whereas, f or the floating-point conversions the precision is the number of digits after the radix point. Other Ways of Using Formatter Till now we saw the use of format method of the Formatter class. We can java code beautifier create a Formatter instance, and use that to invoke the format method. We can create an instance by passing in an Appendable, OutputStream, File or file name. Based on this, the formatted String is stored in an Appendable, OutputStream, File respectively. We can use it with others in the same way. Conclusion In this article, we saw the formatting facilities provided by the java. We saw various syntax that can be used to format the String and the conversion types that can be used for different data types. As usual, the code for the examples we saw can be found.