Java: Comparing two string arrays and removing elements that exist in both arrays

前端 未结 7 1718
余生分开走
余生分开走 2020-12-14 21:38

This is mainly a performance questions. I have a master list of all users existing in a String array AllUids. I also have a list of all end dated users existing in a String

7条回答
  •  天命终不由人
    2020-12-14 22:19

        String s1 = "a,b,c,d";
        String s2 = "x,y,z,a,b,c";
        Set set1 = new HashSet();
        Set set2 = new HashSet();
    
        Set set11 = new HashSet();
    
        String[] splitS1 = s1.split(",");
        String[] splitS2 = s2.split(",");
    
        for(String s3:splitS1){
            set1.add(s3);
            set11.add(s3);
        }
    
        for(String s4:splitS2){
            set2.add(s4);
        }
        set1.removeAll(set2);
        set2.removeAll(set11);
        set1.addAll(set2);
        System.out.println(set1);
    

提交回复
热议问题