title: How can I sort a list in java by another list of ids
body: <p>I have a list of objects in java that looks something like this:</p>
  
  <pre><code>List&lt;Video&gt; videos = new ArrayList&lt;Video&gt;();
  </code></pre>
  
  <p>and my video object looks like this:</p>
  
  <pre><code>public class Video {
      private String nameId;
      private Integer id;
      ...
  }
  </code></pre>
  
  <p>I have another list that just has my nameId strings:</p>
  
  <pre><code>List&lt;String&gt; nameIdList = ArrayList&lt;String&gt;();
  </code></pre>
  
  <p>How can I write a compareto method that doesn't sort my list of videos by comparing each video and instead uses another list? My approach so far has been to use a simple bubble sort but that will be very inefficient as my list gets bigger</p>
  
  <p>Example:</p>
  
  <p>I could have video objects with nameIds : "apple", "bannana", "orange"</p>
  
  <p>and my list of strings to sort them by could be: "bannana", "apple", "orange"</p>
  
  <p>so my videos I would want to return to my client should be in the order of: "bannana", "apple", "orange"</p>