Output in a table format in Java's System.out

前端 未结 8 1419
清歌不尽
清歌不尽 2020-11-22 15:03

I\'m getting results from a database and want to output the data as a table in Java\'s standard output

I\'ve tried using \\t but the first column I want is very vari

8条回答
  •  渐次进展
    2020-11-22 15:44

    Use System.out.format . You can set lengths of fields like this:

    System.out.format("%32s%10d%16s", string1, int1, string2);
    

    This pads string1, int1, and string2 to 32, 10, and 16 characters, respectively.

    See the Javadocs for java.util.Formatter for more information on the syntax (System.out.format uses a Formatter internally).

提交回复
热议问题