Skip to content

ASCIITable | Getting Started

Mitch Talmadge edited this page Oct 2, 2017 · 3 revisions

Tables are simply large Strings. Use the ASCIITable class to configure the table, and toString() to convert it to a String.

The first thing you need to do when using ASCIITable is to ensure that your data is in the correct format.

  • Headers of the table are in a String[] array. Headers go left to right.
  • Data of the table is in a 2D String[][] array, in the format array[row][column]. Newlines are allowed inside the data.

Usage

To use the ASCIITable class, first call the static method ASCIITable#fromData(String[] headers, String[][] data). This creates an ASCIITable instance which you can configure in-line. Once configured, simply call the ASCIITable#toString() method, which returns the table as a String.

A simple example might be:

String[] headers = new String[]{"ID", "Name", "Email"};
String[][] data = new String[][]{
        {"123", "Alfred Alan", "[email protected]"},
        {"223", "Alison Smart", "[email protected]"},
        {"256", "Ben Bessel", "[email protected]"},
        {"374", "John Roberts", "[email protected]"},
};

ASCIITable.fromData(headers, data).toString();

Output