有些代码经常用,却总是忘记,比如说集合去重复。。
今天在博客上记录一下把
最近做项目的时候需要在汇率集合中将币种表里面无效的币种所出现的汇率去掉
//查询出所有汇率
List<ExchangeRate> exchangeRate = userManagementService.getExchangeRate(id);
//查询出被禁用的币种
List<Currency> unableCurrent = t_currencyDao.getCurrencyUnenable();
//将汇率中含有被禁用的币种去除掉
for (int i=0;i<exchangeRate.size();i++){
ExchangeRate exchangeRate = exchangeRate.get(i);
for (int j=0;j<unableCurrent.size();j++){
Currency currency = unableCurrent.get(j);
if (exchangeRate.getGoalCurrencyID().equals(currency.getCurrencyID()) || exchangeRate.getSourceCurrencyID().equals(currency.getCurrencyID())){
exchangeRate.remove(i);
}
}
}