title: How to iterate over the vector in Java and store only the specified class?
body: <p>I have a use case where I need to iterate over the <code>Vector</code> elements and store the results in say array only if that instance is of class <code>method</code></p>
  
  <p>Are there any easy to do this? </p>
  
  <p>Currently I'm doing this way :</p>
  
  <pre><code>    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();
      }
  </code></pre>
  
  <p>But I think there will be some better way than this.</p>