title: Java 8 Stream filtering value of list in a list
body: <p>I have a an object which looks like the following</p>
  
  <pre><code>class MyObject {
  
      String type;
      List&lt;String&gt; subTypes;
  
  }
  </code></pre>
  
  <p>Is it possible, given a list of MyObject's to use Java 8 streams to filter on both the type and then the subtype?</p>
  
  <p>So far I have</p>
  
  <pre><code>myObjects.stream()
      .filter(t -&gt; t.getType().equals(someotherType)
      .collect(Collections.toList());
  </code></pre>
  
  <p>but within this I also want another filter on <em>each</em> of the subTypes filtering those on a particular subtype too.  I can't figure out how to do this.</p>
  
  <p>An example would be</p>
  
  <pre><code>myObject { type: A, subTypes [ { X, Y, Z } ] }
  myObject { type: B, subTypes [ { W, X, Y } ] }
  myObject { type: B, subTypes [ { W, X, Z } ] }
  myObject { type: C, subTypes [ { W, X, Z } ] }
  </code></pre>
  
  <p>I would pass in matchType B and subType Z, so I would expect one result -> myObject type B, subtypes: W, X, Z</p>
  
  <p>the following currently returns 2 items in a list.</p>
  
  <pre><code>myObjects.stream()
      .filter(t -&gt; t.getType().equals("B")
      .collect(Collectors.toList());
  </code></pre>
  
  <p>but I would like to add an additional filter over the each of the subtypes and only matching where 'Z' is present.</p>