줄 은 "기본 형식 double에서 compareTo (double)을 호출 할 수 없습니다"라는 오류 메시지를 표시합니다.. 이 문제를 해결하는 방법?기본 형식 double에서 compareTo (double)을 호출 할 수 없습니다.
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*:: 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.Double 패키지로 이동합니다.이 클래스를 래퍼 클래스라고하고 모든 원시 유형의 Java에서는 해당 래퍼 클래스가 있습니다. java.lang 패키지 –
다음은 문서 링크입니다 http://docs.oracle.com/javase/7/docs/api/ –