title: Java Sort by Distance
body: <p>I have a 2-dimensional array like this:</p>
  
  <pre><code>{1,3,5,6,2,2}
  
  {6,2,4,7,2,1}
  
  {17,28,32,1,35,45}
  
  ...
  </code></pre>
  
  <p>I have a function that can calculate the euclidean distance between any two arrays.  Assuming that the distance function operates correctly, what's the best way to sort the 2-dimensional array so that the arrays within the 2-dimensional array are swapped such that the one's closest to each other(distance wise) would be close to each other in the 2-dimensional array?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Is this boiling down to the travelling salesman problem again?</p>