Note that there are some explanatory texts on larger screens.

plurals
  1. POhow create array of arrays of unequal depth, holding integers only (Android)
    primarykey
    data
    text
    <p>How do I create an array that looks like this: </p> <pre><code>[[1,2,[[3,3,3,3,3],[4,4,4,4,4]],[15,20],35,[2,1]], [2,2,[[6,6,6,6,6],[1,2,3,4,5]],[30,15],45,[2,1]], [2,2,[[6,6,6,6,6],[1,2,3,4,5]],[30,15],45,[2,1]], [2,2,[[6,6,6,6,6],[1,2,3,4,5]],[30,15],45,[2,1]], ...] </code></pre> <p>So a 4-dimensional array, holding integer values only, and with array's within array's but of unequal depth.</p> <p>[edited] Using named elements I would get this declaration: </p> <pre><code>// containerarray spelersSpel: private ArrayList&lt;ArrayList&lt;ArrayList&lt;ArrayList&lt;Integer&gt;&gt;&gt;&gt; spelersSpel_ = new ArrayList&lt;ArrayList&lt;ArrayList&lt;ArrayList&lt;Integer&gt;&gt;&gt;&gt;(); // holding: // first-level element of spelersSpel: private ArrayList&lt;ArrayList&lt;ArrayList&lt;Integer&gt;&gt;&gt; spelerSpel = new ArrayList&lt;ArrayList&lt;ArrayList&lt;Integer&gt;&gt;&gt;(); // holding: // first element of spelerSpel: private int spelerNummer; // second element of spelerSpel: private int spelerBeurtNummer; // third element of spelerSpel: private ArrayList&lt;ArrayList&lt;Integer&gt;&gt;spelerBeurtenWorpenScore = new ArrayList&lt;ArrayList&lt;Integer&gt;&gt;(); // holding: private ArrayList&lt;Integer&gt;spelerBeurtWorpenScore = new ArrayList&lt;Integer&gt;(); // holding: private int spelerBeurtWorpScore; // fourth element of spelerSpel: private ArrayList&lt;Integer&gt;spelerBeurtenTotaal = new ArrayList&lt;Integer&gt;(); // fifth element of spelerSpel: private ArrayList&lt;Integer&gt;spelerBanen = new ArrayList&lt;Integer&gt;(); // holding: private int spelerBaan; </code></pre> <p>and putting values in them like this: </p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); spelerBaan = 2; spelerBanen.add(spelerBaan); spelerSpel.add(spelerBanen); </code></pre> <p>However then I'm still having a problem, on the last line, adding array spelerBanen to spelerSpel, because spelerSpel expects EVERY (first-level) element now to be a two-dimensional array, which spelerBanen isn't. How to solve that? I could think of using a dummy placeholder, like </p> <pre><code>ArrayList&lt;ArrayList&lt;Integer&gt;&gt;dummy = new ArrayList&lt;ArrayList&lt;Integer&gt;&gt;(); dummy.add(spelerBanen); spelerSpel.add(dummy); </code></pre> <p>but that doesn't seem to be a great solution to me either?</p> <p>[edited] My idea would be to change the declaration of spelerSpel to:</p> <pre><code>private ArrayList&lt;ArrayList&lt;ArrayList&lt;Integer&gt;&gt;&gt; spelerSpel = new ArrayList&lt;ArrayList&lt;ArrayList&lt;Integer&gt;&gt;&gt;(5); </code></pre> <p>so with 'fixed' length of 5. and then:</p> <pre><code>spelerBaan = 2; spelerBanen.set(0, spelerBaan); spelerSpel.get(0).set(0,spelerBanen); spelersSpel.add(spelerSpel); </code></pre> <p>I would still be stuck with an array holding a lot of 'dummy' values but I can't figure out how to do it better.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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