Sorting with 2 parameters
Hi all
I am looking to sort an ArrayList with a comparator. I first ordered by hitChi which is from the .getHitChi method. However, hitChi is not unique and duplicates are present. I cannot eliminate these duplicates since they contain other important data.
So is this the correct way to sort using a second parameter, a unique code called hitID or am I likely to get some weird results ?
By the way, I can't sort by HitID the first time around since hitChi is meaningful!
Cheers
Colin
Collections.sort(hitsList,new Comparator<Hit>(){
publicint compare(Hit hit1, Hit hit2){
if (hit2.getHitChi() - hit1.getHitChi() !=0 ){
return hit2.getHitChi() - hit1.getHitChi();
}
else{
return hit2.getHitID() - hit1.getHitID();
}
}
});

