Is there an easy way to output two columns to the console in Java?

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);

Leave a Comment