title: Alternative to instanceof approach in this case
body: <p>Hello I'm wondering what would be some more elegant alternatives to something like this:</p>
  
  <pre><code>class Base...
  
  class A extends Base...
  
  class B extends Base...
  
  //iterator of colection containing mixed As and Bs i want to remowe Bs and do omething with As
  while(iterator.hasNext()) {
      Base next = iterator.next();
      if(next instanceof A) // do something
      if(next instanceof B)
          iterator.remove();
  }
  </code></pre>
  
  <p>Sow what are the alternatives...</p>
  
  <p>Thank you for advices.</p>
  
  <p>edit: Base class may have many subclasses not just two and their numbers may grow in time</p>