How to count the number of specific object in a Vector collection?
I am rather new to Java and have been stuck for hours trying to figure out one thing:
I have a collection of different objects in a Vector<IObject> (all of these objects implement an interface I created called IObject).
How can I count the number of specific objects in my collection?
Let's say I have objects A,B,C that implements IObject, and objects D,E that inherit from C (and thus also implement IObject).
I imagine a function like:
int getObjectCount(String classNameString)
which would return the count of objects named classNameString.
However, if I have, say, two objects D and two objects E in my collection and then call getObjectCount(C.class.getSimpleName()) it must return '4'. (Because C is a supertype of D and E).
Any ideas? I am slowly losing my will to live with this problem...:(
Thanks a lot!;)