I have Price Values like below in String format getting from Custom object
2,000,3,000,5,000,300,-,600,-,507,-
I want to Sort the above Price Values in Ascending and Descending order
Could any one help?
I have tried this:
Comparator<Cars> comparator = new Comparator<Cars>() {
@Override
public int compare(Cars object1, Cars object2) {
// return Float.compare(Integer.parseInt(object1.getPrice()), Integer.parseInt(object2.getPrice()));
String price1=object1.getPrice().replaceAll(",","");
price1=price1.replaceAll("-","");
String price2=object2.getPrice().replaceAll(",","");
price2=price2.replaceAll("-","");
return ((Integer)Integer.parseInt(price1)).compareTo((Integer)Integer.parseInt(price2));
}
};
But if i execute the statement
Collections.sort(carsList, comparator);
getting the Exception
Exception:Error:java.lang.NumberFormatException: Invalid int: ""