Finding if an array contains all elements in another array

后端 未结 5 1165
旧时难觅i
旧时难觅i 2020-11-29 10:53

I am trying to loop through 2 arrays, the outer array is longer then the other. It will loop through the first and if the 2nd array does not contain that int it will return

5条回答
  •  北海茫月
    2020-11-29 11:07

    contain method is reserved for ArrayList Try this:

    public boolean linearIn(int[] outer, int[] inner) {
            for (int i = 0; i < outer.length; i++) {
                for (int j = 0; j < inner.length; j++) {
                    if (outer[i] == inner[j])
                        return false;
                }
            }
            return true;
    }
    

提交回复
热议问题