I have an array of strings called theArray
. All strings in theArray
are of length 20. I wish to display this array in tabular format to view the clustering of a hashing function. This code works, however, it looks horrible. Is there a better way to create tables?
for (int i = 0; i < arraySize; i+=3) {
System.out.println("----------------------------------------------------------------");
System.out.println("| " + i + " | " + (i + 1) + " | " + (i + 2) + " |");
System.out.println("----------------------------------------------------------------");
System.out.println("| " + theArray[i] + "|" + theArray[i+1] + "|" + theArray[i+2]+"|");
}
When this runs, it looks like this:
----------------------------------------------------------------
| 21 | 22 | 23 |
----------------------------------------------------------------
| |Finagle |deciduous |
----------------------------------------------------------------
| 24 | 25 | 26 |
----------------------------------------------------------------
| perennial |condition | |
----------------------------------------------------------------