[Java]去掉两个list中重复的元素

public List<String> removeRepeatFactor(List<String> list1 , List<String> list2)throws Exception{
           if(list1 != null && list2 != null) {
               if (list1.size() != 0 && list2.size() != 0) {
                   Collection A = new ArrayList(list1);
                   Collection B = new ArrayList(list2);
                   A.retainAll(B);
                   if (A.size() != 0) {
                       B.removeAll(A);
                   }
                   return (List<String>) B;
               }
           }
           return list2;
    }

 

posted @ 2019-02-21 09:44  Frankiee  阅读(6863)  评论(0)    收藏  举报