I have a use case where I need to iterate over the Vector elements and store the results in say array only if that instance is of class method
Are there any easy to do this?
Currently I’m doing this way :
Iterator itr = vec.iterator();
Iterator element = vec.iterator();
while(itr.hasNext())
{
boolean method = itr.next() instanceof Method;
if(method)
System.out.println( "\t" + ( (Method)(element.next()) ).name);
else
element.next();
}
But I think there will be some better way than this.
Assume you have a class
Method, then code could be something like :