我有两个数组列表,希望返回两者的差异。下面是我的代码片段:
@ResponseBody
@RequestMapping(value="/unpaidfees", method=RequestMethod.GET, produces="application/json")
public List<Fee> unpaid(@PathVariable("studentid") Long studentid){
Transactions tr = transServ.instalmentalstd(studentid);
List<Fee> allfees = feesServ.allFees();
if(tr != null){
List<Fee> paidfees = transServ.paidfees(tr.getTranxid());
allfees.removeAll(paidfees);
}
return allfees;
}
总而言之。 我有一个包含所有费用的数组列表:
List<Fee> allfees = feesServ.allFees();
第二个数组列表包含已付费用:
List<Fee> paidfees = transServ.paidfees(tr.getTranxid());
我想返回所有费用中存在的费用列表,但不包括已付费用中的费用列表。请告知如何实现这一目标或更好的方法。
感谢您的宝贵时间。
最佳答案
使用removeAll
:
List<Fee> unpaidFees = new ArrayList<>(allfees);
unpaidFees.removeAll(paidfees);
关于java - 在JAVA spring mvc中查找两个数组列表的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34686560/