我有这个:
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)
}
});
我想根据价格对我的数组列表进行排序,但出现此错误:
cannot resolve method compareToIgnoreCase(float)
怎么了
最佳答案
听起来你可能想要:
return Float.compare(offer1.getAmount(), offer2.getAmount());
如果 getAmount()
返回一个 float
- 这意味着您将无法直接调用它的方法,但是 Float.compare
是一个方便的解决方法。
如果 getAmount()
实际上返回一个 Float
(并且您知道它将是非空的),您可以使用:
return offer1.getAmount(),compare(offer2.getAmount());
关于java - 比较 ArrayList 中的 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27800508/