Any Java libraries for drawing ASCII tables?

前端 未结 4 910
北恋
北恋 2021-02-01 19:44

I need to output data into a console as a table. I was wondering maybe there are some java libraries that would take care of drawing tables in ASCII art, aligning values inside

相关标签:
4条回答
  • 2021-02-01 20:12

    Try iNamik Text Table Formatter for Java.

    0 讨论(0)
  • 2021-02-01 20:14

    I like your table and wrote that: https://github.com/klaus31/ascii-art-table

    0 讨论(0)
  • 2021-02-01 20:22

    This worked pretty well for me: http://code.google.com/p/java-ascii-table/

    String [] header = {
          "User Name", 
          "Salary", "Designation",
          "Address", "Lucky#"
    };
    
    String[][] data = {
          { "Ram", "2000", "Manager", "#99, Silk board", "1111"  },
          { "Sri", "12000", "Developer", "BTM Layout", "22222" },
          { "Prasad", "42000", "Lead", "#66, Viaya Bank Layout", "333333" },
          { "Anu", "132000", "QA", "#22, Vizag", "4444444" },
          { "Sai", "62000", "Developer", "#3-3, Kakinada"  },
          { "Venkat", "2000", "Manager"   },
          { "Raj", "62000"},
          { "BTC"},
    };
    

    Which renders the following:

    +-----------+--------+-------------+------------------------+---------+
    | User Name | Salary | Designation |         Address        |  Lucky# |
    +-----------+--------+-------------+------------------------+---------+
    |       Ram |   2000 |     Manager |        #99, Silk board |    1111 |
    |       Sri |  12000 |   Developer |             BTM Layout |   22222 |
    |    Prasad |  42000 |        Lead | #66, Viaya Bank Layout |  333333 |
    |       Anu | 132000 |          QA |             #22, Vizag | 4444444 |
    |       Sai |  62000 |   Developer |         #3-3, Kakinada |         |
    |    Venkat |   2000 |     Manager |                        |         |
    |       Raj |  62000 |             |                        |         |
    |       BTC |        |             |                        |         |
    +-----------+--------+-------------+------------------------+---------+
    
    0 讨论(0)
  • 2021-02-01 20:30

    Here is also a handy library: https://github.com/JakeWharton/flip-tables

    As the doc said:

    String[] headers = { "Test", "Header" };
    String[][] data = {
        { "Foo", "Bar" },
        { "Kit", "Kat" },
    };
    System.out.println(FlipTable.of(headers, data));
    

    should have the following output:

    ╔══════╤════════╗
    ║ Test │ Header ║
    ╠══════╪════════╣    
    ║ Foo  │ Bar    ║
    ╟──────┼────────╢
    ║ Kit  │ Kat    ║
    ╚══════╧════════╝
    
    0 讨论(0)
提交回复
热议问题