Add Filters based on some condition java 8
<p>I need to filter a list of employees based of some parameter like firstName , lastName etc etc. These parameters are user defined user can choose all filter or a combination of filters.</p>

<pre><code>public List&lt;Employee&gt; getFilterList(String firstName,String lastName)
{
    List&lt;Employee&gt; empList = empRepository.getEmployees();

    Stream&lt;Employee&gt; empStream=empList.stream();

   if(firstName!=null)
   {
     empStream= empStream.filter(e-&gt; e.getFirstname().equals(firstName))
   }

   if(lastName!=null)
   {
     empStream= empStream.filter(e-&gt; e.getlastName().equals(lastName))
   }

   return empStream.collect(Collectors.toList());
}
</code></pre>

<p>Is this a correct way of doing this?</p>

<p><strong>Note:</strong> the above code is working fine i am just looking for another better approach (if any).</p>

<p><strong>Case 1:</strong>  <code>getFilterList(null,null)</code> return list of all employees</p>

<p><strong>Case 2:</strong> <code>getFilterList("abc",null)</code> return list of all employees with first name abc.</p>