title: Java - Sort one array based on values of another array?
body: <p>I have an array of Strings that are instances of a class from external code that I would rather not change.</p>
  
  <p>I also have an array of ints that was generated by calling a function on each object. So I have</p>
  
  <p>A:  <code>[string1, string2, string3]</code></p>
  
  <p>And</p>
  
  <p>B:  <code>[40, 32, 34]</code></p>
  
  <p>How do I easily sort A such that it is sorted in by the values of B. I have boost available. I want to sort A such that it is in the order:</p>
  
  <pre><code>[string2, string3, string1]
  </code></pre>
  
  <p>In javascript you could do this like:</p>
  
  <pre><code>B.sort(function(a,b){return A[B.indexOf(a)] &lt; A[B.indexOf(b)];});
  </code></pre>