java - 在JAVA spring mvc中查找两个数组列表的差异

标签 java arrays spring-mvc arraylist

我有两个数组列表,希望返回两者的差异。下面是我的代码片段:

@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/

相关文章:

java - 强制 JButton 不绘制背景

java - 在 JLabel 中绘图

python - 在 Python 2.7 中使用字节

python - 根据用户输入创建 N 维动态数组?

java.lang.ClassNotFoundException : org. springframework.web.servlet.DispatcherServlet 错误

javascript - 向本地主机发送请求时,jQuery xhr.status 返回 0

java - JD-GUI反编译后源码有注释

范围减少的Javascript数组

java - SpringBoot - UnsatisfiedDependencyException Spring Boot 不是扩展 CrudRepository 的 Autowiring Repository 接口(interface)

java - 文件对话框中可接受的扩展名