How can I return the difference between two lists?

后端 未结 10 657
终归单人心
终归单人心 2020-11-27 03:49

I have two array lists e.g.

List a;
contains : 10/10/2014, 10/11/2016

List b;
contains : 10/10/2016

How can i do

10条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 04:33

    Here is a generic solution for this problem.

    public  List difference(List first, List second) {
        List toReturn = new ArrayList<>(first);
        toReturn.removeAll(second);
        return toReturn;
    }
    

提交回复
热议问题