Display Output in Java Console as a Table

Java Console Table Example
Java Console Table Example

If you want to print two-dimensional data just like a table in Java Console with headers, rows, columns, and borders, you can do it by using println function with formatting options - but do there are many external libraries (jars) that can make your life easy and one of them is called java-ascii-table

✌️You can download this project jar from here: https://code.google.com/archive/p/java-ascii-table/downloads

The usage of this library is very simple, create a 1-dimensional header array of Strings, and your data could be a 2-dimensional array. Using the instance of ASCIITable class you can print the table using printTable() function that takes in two parameters String[] header and String[][] data.

package org.code2care;

import com.bethecoder.ascii_table.ASCIITable;

public class JavaConsoleTableExample {

    public static void main(String[] args) {

    String [] tableHeaders = { "Employee Name", "Salary", "Designation","Department"};

    String[][] tableData = {
                { "Mike Kurt", "10000", "Developer", "IT"  },
                { "Steve Musk", "20000", "Lead DevOps", "IT" },
                { "Larry Jobs", "30000", "Java Developer", "IT" },
                { "Elon Peters", "400000", "Manager", "IT" },
                { "Jake Burg", "50000000", "CEO", "IT"  },

        ASCIITable.getInstance().printTable(tableHeaders, tableData);
| Employee Name |  Salary  |   Designation  | Department |
|     Mike Kurt |    10000 |      Developer |         IT |
|    Steve Musk |    20000 |    Lead DevOps |         IT |
|    Larry Jobs |    30000 | Java Developer |         IT |
|   Elon Peters |   400000 |        Manager |         IT |
|     Jake Burg | 50000000 |            CEO |         IT |

As you can see in the above output the table is rendered using dash (-), pipe (|), and plus (+) ASCII characters and it looks really amazing.

✌️Try and explore the printTable method that is overloaded with features that can be used to align the table cell data on console.

public void printTable(String[] header, String[][] data)
public void printTable(String[] header, String[][] data, int dataAlign) 
public void printTable(String[] header, int headerAlign, String[][] data, int dataAlign)
public void printTable(IASCIITableAware asciiTableAware)

Have Questions? Post them here!
Try Out Code2care Dev Tools:


#Android #Java #Linux #Microsoft #Google #Python #MacOS #Notepad++ #Microsoft Teams #CSS #PHP #SharePoint #Html #Linux #C-Program #Bootstrap #jQuery #Sublime #Android-Studio #Facebook #Eclipse #WhatsApp #News #MySQL #Json #HowTos #JavaScript #FTP #S3


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR - https://donate.unhcr.org/in/en-in/ukraine-emergency