Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could have a list of lists, essentially something like so:</p> <pre><code>List&lt;List&lt;String&gt;&gt; table = new ArrayList&lt;List&lt;String&gt;&gt;(); </code></pre> <p>Then add the 26 columns:</p> <pre><code>for(int i = 0; i &lt; 26; i++) { table.add(new ArrayList&lt;String&gt;()); } </code></pre> <p>You can then have a method, called, say, <code>addToColumn(int column, String value, List&lt;List&lt;String&gt;&gt; table)</code> in which you do something like so:</p> <pre><code>for(int i = 0; i &lt; table.size(); i++) { if(i == column) { table.get(i).add(value); } else { table.get(i).add(""); } } </code></pre> <p>This should allow you to have lists which grow together. Of course, my assumption in the above is that you will be entering one element at a time. </p> <p>Alternatively, you can do something like so:</p> <pre><code>public void addToColumns(Map&lt;int, String&gt; data, List&lt;List&lt;String&gt;&gt; table) { for(int key : data.keyset()) { table.get(key).add(data.get(key)); } for(int i = 0; i &lt; table.size(); i++) { if(!data.containsKey(i)) { table.get(i).add(""); } } } </code></pre> <p>The above algorithm should allow you to add items to multiple columns, while filling the rest up with empty strings. This should allow you to end up with rows of equal length. Also, the map will be used to store a key-value pair where the key is the column number, and the value will be whatever string you would like to throw in there. This will allow you to populate your table one row at a time.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload