title: Search an attribute inside a Vector on Java
body: <p>I've a <code>Vector</code> of objects, and have to search inside for a random attribute of those objects (For example, a <code>Plane</code> class, a <code>Vector</code> containing <code>Plane</code>; and I've to search sometimes for <code>destination</code>, and others to <code>pilotName</code>).</p>
  
  <p>I know I can traverse the <code>Vector</code> using an <code>Iterator</code>, but I've got stuck at how do I change the comparison made between a String and the attribute on the object. I thought of using <code>switch</code>, but a another opinion would be cool.</p>
  
  <hr>
  
  <p><strong>Update 1:</strong></p>
  
  <p>The code I've written is something like this (Java n00b alert!):</p>
  
  <pre><code>public int search(String whatSearch, String query){  
      int place = -1;  
      boolean found = false;  
      for ( Iterator&lt;Plane&gt; iteraPlane = this.planes.iterator(); iteraPlane.hasNext() &amp;&amp; found == false; ) {  
          Plane temp = (Plane) iteraPlane.next();  
          /* Here is where I have to search for one of many attributes (delimited by whatSearch */ 
      }  
  return place;  
  }
  </code></pre>
  
  <p>Seems I've to stick to linear search (and that's a price I've able to pay). Anyway, I was thinking if Java had something like <em>variable variable name</em> (ouch!)</p>