new Formatter(Appendable a) : Formatter « java.util « Java by API






new Formatter(Appendable a)

/*
   2)+1234.12
 */
import java.util.Formatter;

public class MainClass {

  public static void main(String[] args) throws Exception {
    StringBuilder buf = new StringBuilder(); // Buffer to hold output
    Formatter formatter = new Formatter(buf); // Formatter to format data into
                                              // buf
    formatter.format("%4d)%+7.2f", 2, 1234.1234);
    System.out.println(buf);

  }

}

           
       








Related examples in the same category

1.Formatter: format('%.15s', String str) (Display at most 15 characters in a string)
2.Formatter: format('%.4f', 123.1234567) (Format 4 decimal places)
3.Formatter: format('%4d %4d %4d', 1, 2, 3)
4.Formatter: format('%16.2e', 123.1234567) (Format to 2 decimal places in a 16 character field)
5.Formatter: format('|%10.2f|', 123.123) (Right justify by default)
6.Formatter: format('|%f|%n|%12f|%n|%012f|', 10.12345, 10.12345, 10.12345) (a field-width specifier)
7.Formatter: format('|%-10.2f|', 123.123) ( left justify )
8.Formatter: format('% d', -100) (the space format specifiers)
9.Formatter: format('%g', i)
10.Formatter: format('%n %d%% ', 88) (the %n and %% format specifiers)
11.Formatter: format('%tB %tb %tm', cal, cal, cal) (Display month by name and number)
12.Formatter: format('%tc', cal) (Display complete time and date information)
13.Formatter: format('%te of % < tB, % < tY', cal)
14.Formatter: format('%tl:%tM', cal, cal) (Display just hour and minute)
15.Formatter: format('%tr', cal) (Display standard 12-hour time format)
16.Formatter: format(String format, Object... args)