How can I return the difference between two lists?

后端 未结 10 667
终归单人心
终归单人心 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:27

    You may call U.difference(lists) method in underscore-java library. I am the maintainer of the project. Live example

    import com.github.underscore.U;
    import java.util.Arrays;
    import java.util.List;
    
    public class Main {
        public static void main(String[] args) {
            List list1 = Arrays.asList(1, 2, 3);
            List list2 = Arrays.asList(1, 2);
            List list3 = U.difference(list1, list2);
            System.out.println(list3);
            // [3]
        }
    }
    

提交回复
热议问题