Class TablePrinter

java.lang.Object
org.javalite.common.TablePrinter

public class TablePrinter extends Object
Prints a two dimensional array to STDIO as a formatted table. Width of columns will be automatically adjusted based on data.

Usage:

     String[][] table = new String[][] {
             { "id", "First Name", "Last Name", "Age" },
             { "1", "John", "Johnson", "45" },
             { "2", "Tom", "", "35" },
             { "3", "Rose", "Johnson", "23"},
             { "4", "Jimmy", "Kimmel", "" }
     };
     TablePrinter.printTable(table);
 
The above will result in this output:
 +----+------------+-----------+-----+
 | id | First Name | Last Name | Age |
 +----+------------+-----------+-----+
 | 1  | John       | Johnson   | 45  |
 | 2  | Tom        |           | 35  |
 | 3  | Rose       | Johnson   | 23  |
 | 4  | Jimmy      | Kimmel    |     |
 +----+------------+-----------+-----+
 
This code was stolen... ehhr borrowed from: Printing to CONSOLE in TABLE format.
  • Constructor Details

    • TablePrinter

      public TablePrinter()
  • Method Details

    • main

      public static void main(String[] args)
    • printTable

      public static void printTable(String[][] table)
      Expects a two-dimensional array of strings. Does not tolerate null values. ALl cells must be String instances.