title: Java 8 Lambda - Intersection of Two Lists
body: <p>I am trying to find <code>intersection</code> of two lists based on some condition and doing some steps. Couldn't find a way to do it (in learning stage) :)</p>
  
  <pre><code>Double totalAmount = 0.00d;
  Double discount = 0.00d;
  
  
  List&lt;OrderLineEntry&gt; orderLineEntryList = orderEntry.getOrderReleases().stream()
      .flatMap(orderReleaseEntry -&gt; orderReleaseEntry.getOrderLines().stream())
      .filter(orderLineEntry -&gt; orderLineEntry.getStatus().equals("PP") || orderLineEntry.getStatus().equals("PD"))
      .collect(Collectors.toList());
  
  for (OrderLineEntry orderLineEntry : orderLineEntryList) {
      for (SplitLineEntry splitLineEntry : splitReleaseEntry.getLineEntries()) {
          if (splitLineEntry.getOrderLineId().equals(orderLineEntry.getId()) &amp;&amp; splitLineEntry.getStatusCode() != "PX") {
              totalAmount += orderLineEntry.getFinalAmount();
              couponDiscount += orderLineEntry.getCouponDiscount() == null ? 0.00d : orderLineEntry.getCouponDiscount();
          }
      }
  }
  </code></pre>
  
  <p>As you see, the logic is simple</p>
  
  <p>Get All items from order based on some filter <code>list</code> and intersect with another <code>list</code> and do some stuff.</p>