public static String prettyPrintGrid(List<List<String>> lines) {
        int numColumns = -1;
        int rowIndex = 0;
        for (List<String> col : lines) {
            if (numColumns == -1) {
                numColumns = col.size();
            } else if (numColumns != col.size()) {
                throw new RuntimeException("Expected " + numColumns + " columns in row " +
                    rowIndex + ", but got " + col.size());
            }
            rowIndex++;
        }
        List<Integer> widths = new ArrayList<>(numColumns);
        for (int x = 0; x < numColumns; x++) {
            int w = 0;
            for (List<String> cols : lines) {
                w = Math.max(w, cols.get(x).length() + 1);
            }
            widths.add(w);
        }
        StringBuilder bld = new StringBuilder();
        for (List<String> cols : lines) {
            for (int x = 0; x < cols.size(); x++) {
                String val = cols.get(x);
                int minWidth = widths.get(x);
                bld.append(val);
                for (int i = 0; i < minWidth - val.length(); i++) {
                    bld.append(" ");
                }
            }
            bld.append(String.format("%n"));
        }
        return bld.toString();
    }
Formats strings in a grid pattern.

All entries in the same column will have the same width.

@param lines     A list of lines.  Each line contains a list of columns.
                 Each line must contain the same number of columns.
@return          The string.
trogdor/src/main/java/org/apache/kafka/trogdor/common/StringFormatter.java