I have this :
Offers eoResponse = eoClient.getOffers(url);
Collections.sort(eoResponse, new Comparator<Offer>() {
public int compare(Offer offer1, Offer offer2) {
return offer1.getAmount().compareToIgnoreCase(offer2.getAmount()); // errors in this line cannot resolve method compareToIgnoreCase(float)
}
});
i want to sort my arraylist compared to prices, but i have this error :
cannot resolve method compareToIgnoreCase(float)
what's wrong
It sounds like you probably want:
return Float.compare(offer1.getAmount(), offer2.getAmount());
That's if getAmount()
returns a float
- that means you won't be able to call methods on it directly, but Float.compare
is a handy workaround.
If getAmount()
actually returns a Float
(and you know it'll be non-null) you can use:
return offer1.getAmount(),compare(offer2.getAmount());
See more on this question at Stackoverflow