title: Java Stream API - count items of a nested list
body: <p>Let's assume that we have a list of countries: <code>List&lt;Country&gt;</code> and each country has a reference to a list of its regions: <code>List&lt;Region&gt;</code>  (e.g. states in the case of the USA). Something like this:</p>
  
  <pre class="lang-none prettyprint-override"><code>USA
    Alabama
    Alaska
    Arizona
    ...
  
  Germany
    Baden-Württemberg
    Bavaria
    Brandenburg
    ...
  </code></pre>
  
  <p>In "plain-old" Java we can count all regions e.g. this way:</p>
  
  <pre><code>List&lt;Country&gt; countries = ...
  int regionsCount = 0;
  
  for (Country country : countries) {
      if (country.getRegions() != null) {
          regionsCount += country.getRegions().size();
      }
  }
  </code></pre>
  
  <p>Is it possible to achieve the same goal with Java 8 Stream API? I thought about something similar to this, but I don't know how to count items of nested lists using <code>count()</code> method of stream API:</p>
  
  <pre><code>countries.stream().filter(country -&gt; country.getRegions() != null).???
  </code></pre>