Specify Formatter a Minimum Field Width in Java
Description
The following code shows how to specify Formatter a Minimum Field Width.
An integer between the % sign and the format conversion code acts as a minimum field width specifier.
The default padding is done with spaces.
If you want to pad with 0's, place a 0 before the field width specifier.
For example, %05d will pad a number of less than five digits with 0's.
Example
/*from w w w.ja v a 2 s . com*/
import java.util.Formatter;
public class Main {
public static void main(String args[]) {
Formatter fmt = new Formatter();
fmt.format("%05d", 88);
System.out.println(fmt);
}
}
The code above generates the following result.