Java – n easy way to output two columns to the console in Java

java

As the title says, is there an easy way to output two columns to the console in Java?

I'm aware of \t, but I haven't found a way to space based on a specific column when using printf.

Best Solution

Use the width and precision specifiers, set to the same value. This will pad strings that are too short, and truncate strings that are too long. The '-' flag will left-justify the values in the columns.

System.out.printf("%-30.30s  %-30.30s%n", v1, v2);