Finding if an array contains all elements in another array

后端 未结 5 1173
旧时难觅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:05

    int[] is a primitive array. Meaning it does not have any special methods attached to it. You would have to manually write your own contains method that you can pass the array and the value to.

    Alternatively you could use an array wrapper class such as ArrayList which does have a .contains method.

    ArrayList inner = new ArrayList();
    boolean containsOne = inner.contains(1);
    

提交回复
热议问题