Java text formatting

How can I format a line of text such as first name, last name, phone, etc. to look like columns?

it will not be:

String customer = "\t"+surname+"\t"+givenname+"\t"+blablabla

+3
source share
3 answers

See the documentation for String.format(). Use the maximum length that each column can be, plus 1.

+8
source

The problem with using tabs is that their width depends on the settings of the console that you use to display, which means that you cannot guarantee that all columns will be aligned using this approach.

, , . .

+2

There are several libraries in the wild wilderness that can do this for you - with a common limitation that will usually work with monospaced fonts (e.g. Courier). One of these libraries is the iNamik Text Table Formatter for Java , but if you use Google for search java text tableyou will find a lot more.

+2
source

Source: https://habr.com/ru/post/1719267/


All Articles