title: How do I get length of list of lists in Java?
body: <p>If I have a <code>List&lt;List&lt;String&gt;&gt;</code> data in Java, I can get the length of the first list via code:</p>
  
  <pre><code>int lengthData = data.get(0).size();
  </code></pre>
  
  <p>But how do I get the number of lists in the structure without traversing the list of lists to find out?</p>
  
  <p>Maybe I've been a bit unclear. I have the structure:</p>
  
  <pre><code>List&lt;List&lt;String&gt;&gt; data 
  </code></pre>
  
  <p>And I see that:</p>
  
  <pre><code>int i = data.size();
  </code></pre>
  
  <p>Will equal 1 because it is the root list. So what I want to know is how many sublists there are. Traversal of the structure like this:</p>
  
  <pre><code>for (List&lt;String&gt; l : data) {                     
       total ++;                
  }
  </code></pre>
  
  <p>Only gives me a result of 1 which I find odd.</p>
  
  <p>I have data of the form:</p>
  
  <pre><code>List 1 ==&gt; 1, 2, 3, 4
  List 2 ==&gt; 3, 8. 9, 1
  </code></pre>
  
  <p>And so on where these are sublists of the root list.</p>