Accumulation summary: java array matching judgment, find the intersection

To determine whether two arrays have the same elements is to find the
intersection. The function of intersection is not retainAll. The code is as follows:

boolean has = false;
String[] strOne= {
    
    "c","b","a","d"};
String[] strTwo= {
    
    "a","b","d","g"};
HashSet<String> set = new HashSet<>(Arrays.asList(strOne));
set.retainAll(Arrays.asList(strTwo));
if(set.size() > 0){
    
    
    has =  true;
}

Guess you like

Origin blog.csdn.net/weixin_41812784/article/details/108776829