1 回答

TA貢獻1851條經驗 獲得超3個贊
under20.remove(item);是使用值進行調用。它期待鑰匙。你也不能只是改為迭代和調用,因為你會有一個.removeunder20.keySet()removeConcurrentModificationException
解決它的一種簡單方法是創建另一個地圖:
Map<String, ExchangeSummaryItem> result = new HashMap<>();
//Map.entrySet() gives you access to both key and value.
for (Map.Entry<String,ExchangeSummaryItem> item : under20.entrySet()) {
int ObjSellAverage = item.getValue().getSellAverage();
int ObjSellQ = item.getValue().getSellQuantity();
int ObjBuyQ = item.getValue().getBuyQuantity();
if (!(ObjSellAverage > 20000 && ObjSellQ == 0 && ObjBuyQ == 0)){
result.put(item.getKey(), item.getValue());
}
}
并在result
添加回答
舉報