Java: select from collection only elements of provided type
- by glaz666
Hi!
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.
Is there any way to do it except:
for (A a : initCollection) {
if (a instance of B) {
newCollection.add(a)?
}
}
Thanks