How to use String.format() in Java to replicate tab “\t”?

前端 未结 3 1845
名媛妹妹
名媛妹妹 2020-12-15 07:19

I\'m printing data line by line and want it to be organized like a table.

I initially used firstName + \", \" + lastName + \"\\t\" + phoneNumber.

<
3条回答
  •  Happy的楠姐
    2020-12-15 07:50

    The only alternative is loop the names list, calculate the maximum length of the String, and add whitespaces as needed after every name to ensure that all the numbers begin at the same column.

    Using tabs has the disavantage that you cannot know a priori how many whitespace are equivalent to a tab, since it is dependent of the editor.

提交回复
热议问题