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();
    }
@Test
    public void testPrettyPrintGrid() {
        assertEquals(String.format(
                "ANIMAL  NUMBER INDEX %n" +
                "lion    1      12345 %n" +
                "manatee 50     1     %n"),
            StringFormatter.prettyPrintGrid(
                Arrays.asList(Arrays.asList("ANIMAL", "NUMBER", "INDEX"),
                    Arrays.asList("lion", "1", "12345"),
                    Arrays.asList("manatee", "50", "1"))));
    }