Simple way to compare 2 ArrayLists

后端 未结 10 1864
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 00:50

I have 2 arraylists of string object.

List sourceList = new ArrayList();
List destinationList = new ArrayList

        
10条回答
  •  时光说笑
    2020-11-30 01:20

    boolean isEquals(List firstList, List secondList){
        ArrayList commons = new ArrayList<>();
    
        for (String s2 : secondList) {
            for (String s1 : firstList) {
               if(s2.contains(s1)){
                   commons.add(s2);
               }
            }
        }
    
        firstList.removeAll(commons);
        secondList.removeAll(commons);
        return !(firstList.size() > 0 || secondList.size() > 0) ;
    }
    

提交回复
热议问题