title: Java: iterating through one list in order of the objects in other list
body: <p>I have a List of object, <code>List&lt;Field&gt; fieldList</code> and a list of String <code>List&lt;String&gt; fieldNameList</code>.
  Each Field object in the <code>fieldList</code> consists of String <code>filedName</code> and various properties. </p>
  
  <p>What is the best way to iterate over the <code>fieldList</code> and access their properties in the order of the <code>fieldNameList</code>?</p>
  
  <p>For example,</p>
  
  <p><code>fieldList</code>: <code>[name, color, size]</code></p>
  
  <p>contains:  </p>
  
  <blockquote>
  <pre><code>  [field1, red, 10]
    [field2, yellow, 8]
    [filed3, green, 9]
    [field4, blue, 10]
  </code></pre>
  </blockquote>
  
  <p>And the <code>fieldNameList</code> contains:</p>
  
  <blockquote>
  <pre><code>  [field2, field3, field1, field4]
  </code></pre>
  </blockquote>
  
  <p>I want to access the <em>fieldList</em> in order of the <em>fieldNameList</em>, i.e.
          color = yellow, green, red, blue</p>
  
  <p>One way that I know is to iterate through the <code>fieldList</code> first and create a <code>HashMap&lt;String, Field&gt; nameFieldMap</code> and then iterate through the <code>fieldNameList</code> and access the required field properties by the <code>fieldNames</code> in order. </p>
  
  <p>However, this involves 2 iterations and hence the <strong>time taken would be 2n</strong>. </p>
  
  <blockquote>
    <p>Is there a better way to do this? Can this be achieved in one
    iteration?</p>
  </blockquote>