我有一个数组,而不是一个arrayList,我想对它排序。 这只能告诉我,集合是不适用的参数(pixelPlaceSort.Pixel [],...等等。排序数组而不是ArrayList
Collections.sort(pixels, new PixelComparator());
我可以用一个列表来解决,但对于学习的目的我不知道希望这样。
那么如何才能这项工作? c是一个int。
class PixelComparator implements Comparator<Pixel> {
PixelComparator() {
}
public int compare(Pixel p1, Pixel p2) {
if(p1.c < p2.c) {
return -1;
} else if(p1.c > p2.c) {
return 1;
}
else {
return 0;
}
}
}
下次试试Google! “java排序数组”可能已经工作 –
吨重复:http://stackoverflow.com/questions/1694751/java-array-sort-descending,http://stackoverflow.com/questions/215271/sort-arrays-of -primitive-type-in-des-order-order等等 – kostja
我真的做了搜索!主要发现了Integer将用于解决问题或转换为列表并转换回来的东西。但也许我应该搜索一些更长的时间,谢谢那个 – clankill3r