title: Find number of elements across multiple lists and combine; remove if/else complex?
body: <p>I have a list of lists:</p>
  
  <pre><code>List&lt;List&lt;String&gt;&gt; someList = new List&lt;List&lt;&gt;&gt;();
  </code></pre>
  
  <p>The maximum size of a list is five strings. It's something like below:</p>
  
  <pre><code>someList.get(0).size(); // 4 elements
  someList.get(1).size(); // 1 elements
  someList.get(2).size(); // 3 elements
  someList.get(3).size(); // 1 elements
  ...
  </code></pre>
  
  <p>I'm trying to devise a method to create a new list of a specific size (1-5 elements) by combining some of the above nested lists. I could do something like the below (in this example, three elements):</p>
  
  <pre><code>public List&lt;String&gt; getThree() {
      for (int j = 0; j &lt; someList.size(); j++) {
          //look for nested lists of size 3
          if (someList.get(j).size() == 3) {
              return someList.get(j);
          }
      for (int j = 0; j &lt; someList.size(); j++) {
          //if found nested list of size 2, find one of size 1 to combine
          if (someList.get(j).size() == 2) {
              for (int k = 0; k &lt; someList.size(); k++) {
                  if (someList.get(k).size() == 1) {
                      return someList.get(j).add(someList.get(k).get(0));
                  }
              }
          }
      for (int j = 0; j &lt; someList.size(); j++) {
          //if found nested list of size 1, find one of size 2 to combine
          if (someList.get(j).size() == 1) {
              for (int l = 0; l &lt; someList.size(); l++) {
                  if (someList.get(l).size() == 2) {
                      return someList.get(j).addAll(someList.get(l));
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>I haven't included the loop for if no sublists are of size 2, to find three of size 1, but you can imagine how long and how ugly it can get. The order is important, thus the for loops incrementing sequentially (ie. I'd rather combine subList 1 + 2 more than 2 + 3, 1 + 3 more than 2 + 3, etc).</p>
  
  <p>I'm hoping to find a way to dynamically implement this. I can only fathom how unreadable and long the <code>getFive</code> method will be provided my current methodology. I have multiple methods (getOne through getFive), it doesn't need to be dynamic in this sense, I'd just like to get rid of a lot of the if/else and for loops to reduce complexity and improve readability.</p>
  
  <p>I should mention this is homework related, so I don't quite want a specific answer, but a nudge in the right direction. Something <code>modulo</code> perhaps? To do with remainders?</p>
  
  <p>edit; to clarify and give an example:</p>
  
  <pre><code>aList = new List&lt;String&gt;;
  aList.add("a");
  aList.add("b");
  someList.add(aList);
  bList = new List&lt;String&gt;;
  bList.add("c");
  someList.add(bList);
  newList = someList.getThree();
  //newList.size() == 3
  //newList contains "a","b","c"
  </code></pre>
  
  <p>The <code>getThree()</code> method is creating a new list comprised of elements from the sublists of <code>someList</code>. It cannot split a sublist (ie. it can't take 1 element from a sublist of 2 elements), it's combining whole sublists.</p>