title: Java: select from collection only elements of provided type
body: <p>I have a collection of elements of type B and C, which all extends A. I need to filter the collection to get elements of only B type. </p>
  
  <p>Is there any way to do it except:</p>
  
  <pre><code>for (A a : initCollection) {
    if (a instanceof B) {
      newCollection.add(a)?
    }
  }
  </code></pre>
  
  <p>Thanks</p>