title: Filter values only if not null using lambda in Java8
body: <p>I have a list of objects say <code>car</code>. I want to filter this list based on some parameter using Java 8. But if the parameter is <code>null</code>, it throws <code>NullPointerException</code>. How to filter out null values?</p>
  
  <p>Current code is as follows</p>
  
  <pre><code>requiredCars = cars.stream().filter(c -&gt; c.getName().startsWith("M"));
  </code></pre>
  
  <p>This throws <code>NullPointerException</code> if <code>getName()</code> returns <code>null</code>.</p>