title: Cannot invoke compareTo(double) on the primitive type double
body: <p>The line <code>return array[index1].compareTo(array[index2]);</code> provides an error <strong>"Cannot invoke compareTo(double) on the primitive type double"</strong>. How to solve this issue?</p>
  
  <pre><code>/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
  /*::  This function implements a comparator of double values        :*/
  /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
  private class ArrayIndexComparator implements Comparator&lt;Integer&gt;
  {
      private final double[] array;
  
      public ArrayIndexComparator(double[] array)
      {
          this.array = array;
      }
  
      public Integer[] createIndexArray()
      {
          Integer[] indexes = new Integer[array.length];
          for (int i = 0; i &lt; array.length; i++)
          {
              indexes[i] = i; // Autoboxing
          }
          return indexes;
      }
  
      @Override
      public int compare(Integer index1, Integer index2)
      {
           // Autounbox from Integer to int to use as array indexes
          return array[index1].compareTo(array[index2]);
      }
  }
  
  
  double[] dist = new double[centroids.size()];
  // fill array...    
  ArrayIndexComparator comparator = new ArrayIndexComparator(dist);
  Integer[] indexes = comparator.createIndexArray();
  Arrays.sort(indexes, comparator);
  </code></pre>