लाइन return array[index1].compareTo(array[index2]);
एक त्रुटि प्रदान करता है "तुलनात्मक प्रकार डबल ( पर तुलना करने के लिए (डबल) नहीं आ सकता है। इस मुद्दे को कैसे हल करें?तुलनात्मक रूप से टाइप नहीं कर सकते हैं (डबल) आदिम प्रकार पर डबल
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*:: This function implements a comparator of double values :*/
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
private class ArrayIndexComparator implements Comparator<Integer>
{
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 < 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);
डबल क्लास का उपयोग करें;) – Alessio
अधिक जानने के लिए जावा दस्तावेज पर जाएं और उसके भीतर पैकेज java.lang पर जाएं। डबल, इसे प्रत्येक प्राचीन प्रकार के लिए रैपर क्लास और जावा में कहा जाता है, इसी प्रकार के रैपर वर्ग मौजूद होते हैं java.lang पैकेज –
यहां दस्तावेज़ों के लिए लिंक है http://docs.oracle.com/javase/7/docs/api/ –