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?
We've seen that Java isn't just useful for big web applications - it works just fine for short-running CLI applications too, made easier with jbang and picocli. This was just an example though - Twilio already has a very useful CLI already which can send SMS and do a lot more besides.
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();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With