Hi All,
Below is a comparator that sorts numbers in ascending order starting with the smallest. I want to reverse this so that it sorts numbers in descending order, the largest number appearing first and so on.
Thanks for any help
public static Comparator myComparator = new Comparator(){
public int compare(Object value1, Object value2) {
String sVal1 = ((value1Entity)value1)getV
alue();
String sVal2 = ((value1Entity)value2)getV
alue();
int iVal1 = 0;
int iVal2 =0;
try { iVal1=(int)Float.parseFloa
t(sVal1); }
catch(NumberFormatExceptio
n e) { }
try { iVal2=(int)Float.parseFloa
t(sVal2); }
catch(NumberFormatExceptio
n e) { }
if(iVal1 == 0)
iVal1 = 9999;
if(iVal2 == 0)
iVal2 = 9999;
if(iVal1<iVal2)
return 1;
else if(iVal2<iVal1)
return -1;
else //(iVal2==iVal1)
return 0;
}
};
Start Free Trial