...

반응형
Collections.sort(arrData, new Comparator<CustomData>() {
@Override
public int compare(CustomAppearNumberData o1, CustomAppearNumberData o2) {

if(o1.getCount() > o2.getCount())
{
return -1;
}
else
{
return 1;
}
}
});


보통 위와 같이 sort 함수를 사용하는데요 

가끔 Comparison method violates its general contract! 에러가 날때가 있습니다


이럴때는 아래와 같이 추가 해주시면 해결 할 수 있습니다


Collections.sort(arrData, new Comparator<CustomData>() {
@Override
public int compare(CustomAppearNumberData o1, CustomAppearNumberData o2) {

if(o1.getCount() > o2.getCount())
{
return -1;
}
else if(o1.getCount() == o2.getCount())
{
return 0;
}
else
{
return 1;
}
}
});


반응형