Reputation: 752
Does anybody know a library that would transform a String[][] into a String table as below?
| title1 | title2 | |________|________| | blah | blih | | blah2 | blih2 | etc...
I could write formatted strings for this, but it will be non-generic code, tied to the parameters. Writing generic code for this purpose would be more expensive than what I'm willing to invest.
So all in all, I think a library would be justified for this.
Any idea if this exists already?
Upvotes: 5
Views: 6579
Reputation: 76
According to daniel_or_else in this thread:
Using j-text-utils you may print to console a table like:
_____________________________________________________________
| Item Num | Description | Rating | Cost | Price |
=============================================================
| 8675309 | Tommy Tutone Album | 3 | 5.99 | 10.99 |
| 5619452 | Led Zeppelin Box Set | 5 | 10.42 | 24.95 |
| 9154732 | Justin Bieber Box Set | -1 | 0.00 | 0.00 |
And it as simple as:
TextTable tt = new TextTable(columnNames, data);
tt.printTable();
Upvotes: 6
Reputation: 274788
I am not aware of any library that does this, but take a look at this SO question:
Java: Print a 2D String array as a right-justified table
It shows you how you can create a generic method which dynamically-generates format strings for each column.
Upvotes: 1