title: Java 8 using stream, flatMap and lambda
body: <p>I have this piece of code and I want to return a list of postCodes:</p>
  
  <pre><code>List&lt;String&gt; postcodes = new ArrayList&lt;&gt;();
  List&lt;Entry&gt; entries = x.getEntry(); //getEntry() returns a list of Entry class
  for (Entry entry : entries) {
      if (entry != null) {
         Properties properties = entry.getContent().getProperties();
         postcodes.addAll(Arrays.asList(properties.getPostcodes().split(",")));
     }
  } 
  return postcodes;
  </code></pre>
  
  <p>Here's my attempt to use stream() method and the following chained methods:</p>
  
  <pre><code>...some other block of code
  List&lt;Entry&gt; entries = x.getEntry.stream()
      .filter(entry -&gt; recordEntry != null)
      .flatMap(entry -&gt; {
          Properties properties = recordEntry.getContent().getProperties();
          postCodes.addAll(Arrays.asList(properties.getPostcodes().split(",")));
  });
  </code></pre>