title: Dealing with a null attribute using java 8 streams and sorting using lambda expressions
body: <p>Let's consider a <code>Parent</code> class which contains only one <code>Integer</code> attribute. I created 6 objects of parent class and values of attribute are <code>100, 20, 300, 400, 500, null</code>.</p>
  
  <p>Now I added all the objects to a list(Name of list is list). Then I want to get the objects whose attribute value is greater than <code>100</code>. I used Java 8 streams for this purpose.</p>
  
  <pre><code>Predicate&lt;Entity&gt; predicate = e -&gt; e.getParentId() &lt; 100;
  result = list.stream().filter(predicate).collect(Collectors.toList());
  </code></pre>
  
  <p>I also want to sort the list in descending order. I used the following code for this purpose.</p>
  
  <pre><code>Comparator&lt;Entity&gt; comp = (d1,d2) -&gt; d2.getId().compareTo(d1.getId());
  list.sort(comp);
  </code></pre>
  
  <p>In both cases I get a <code>NullPointerException</code>.</p>
  
  <p>How to handle this?</p>