title: Find all combinations of an ArrayList of ArrayLists of user defined objects
body: <p>I have defined a class <code>Note</code> that represents a way to play a certain note (two integers for the string and fret on a string instrument), and a class <code>Chord</code> which has an ArrayList of all the notes in that chord.</p>
  
  <p>For every note that is played there may be multiple ways of playing that note so I have an ArrayList of Notes representing each possible way. In a chord there can be any number of notes so I have an ArrayList of ArrayLists of Notes. From this I want to create an ArrayList of chords with each possible way of playing the chord.</p>
  
  <p>I have defined a constructor <code>Chord(ArrayList&lt;Note&gt; notes)</code></p>
  
  <p>eg:
  Note A has 3 ways of being played and note B 2 ways of being played, from this I would want chords with:</p>
  
  <p>[A1,B1], [A1,B2], [A2 B1], [A2 B2], [A3,B1], [A3,B2].</p>
  
  <p>I have created a method that works under the assumption that there are always 3 notes played but can't think how to expand it to work for an unknown number</p>
  
  <pre><code>public static ArrayList&lt;Chord&gt; allPlayable(ArrayList&lt;ArrayList&lt;Note&gt;&gt; candidates)
  {
      ArrayList&lt;Chord&gt; allPlayable = new ArrayList&lt;&gt;();
  
      for (int i = 0; i &lt; candidates.get(0).size(); i++)
      {
          Note n0 = candidates.get(0).get(i);
  
          for (int j = 0; j &lt; candidates.get(1).size(); j++)
          {
              Note n1 = candidates.get(1).get(j);
  
              for (int k = 0; k &lt; candidates.get(2).size(); k++)
              {
                  Note n2 = candidates.get(1).get(k);
  
  
                  ArrayList&lt;Note&gt; chordNotes = new ArrayList&lt;&gt;();
  
                  chordNotes.add(n0);
                  chordNotes.add(n1);
                  chordNotes.add(n2);
  
                  allPlayable.add(new Chord(chordNotes));
  
              }
          }
      }
  
      return allPlayable;
  }
  </code></pre>