How to print a 2D array with varying sized cells?
<p>I have a 2-D array where each cell is a Set. 
In each set is a different size, say for example, ranging from 0 to 5.</p>

<p>I want to print out the 2-D array in a format such that it's easily readable.</p>

<p>Example</p>

<pre><code>HashSet&lt;String&gt;[][] schedule = (HashSet&lt;String&gt;[][]) new HashSet[3][5];
schedule[0][0].add("A");
schedule[0][0].add("B");
schedule[0][0].add("C");

schedule[0][2].add("D");
schedule[0][2].add("E");

schedule[1][0].add("F");
schedule[1][1].add("G");

schedule.print();
</code></pre>

<p>will produce</p>

<pre><code>-----------------
| A |   | D | | |
| B |   | E | | |
| C |   |   | | |
-----------------
| F | G |   | | |
-----------------
|   |   |   | | |
-----------------
</code></pre>

<p>obviously without the '-' and '|', but you get the point.</p>

<p>The only viable solution I can think of is creating and remembering the iterator for each column (so remembering 5 iterators at the same time) and iterating through each column, outputting one element at a time until there are no more elements in any of the iterators.</p>

<p>One problem is that in the case of G, it expands the second column even though there are not any values in the first row, second column. I can get around this by buffering each column with tabs.</p>

<p>Obviously this hack does not scale with additional columns, so I was wondering if there were any cute tricks that I might have forgotten.</p>

<p>Thanks!</p>
