title: Cast from List<A> to List<B> when B extends A
body: <p>I have two clases:</p>
  
  <pre><code>public class A {
     //attibutes and methods
  }
  
  public class B extends A {
     //atributes and methods
  }
  </code></pre>
  
  <p>Now I have a service that returns a <strong><em>List with elements of type A</em></strong>. Lets call it <strong><em>generateAElements()</em></strong>;</p>
  
  <p>I want to <strong><em>call that method</em></strong>, <strong><em>filter the List</em></strong> obtained to only <strong><em>keep the elements of type B</em></strong>, which also are of type A.</p>
  
  <pre><code>List&lt;A&gt; listA = generateAElements();
  List&lt;A&gt; listAA = listA.filter( p -&gt; p instanceof B).collect(Collectors.toList());
  List&lt;B&gt; listB = new ArrayList&lt;&gt;();
  // need to create a new list, iterate overListA and add elements of type B?
  for (A itemA : listA) {
      listB.add((B) itemA);       
  }
  </code></pre>
  
  <p>Is there an efficient way to do this? </p>
  
  <p>Important: The list may contain a large number of elements. </p>