Best way to check if an array of primitives contains all the primitives in another array

I am looking for a better way to check if an array of primitives contains all the primitives in another array in Java. For instance:

int[] a = new int[]{1,2};
int[] b = new int[]{1,2,3,4,5};
int[] c = new int[]{2,4,6};

containsAll(b, a); //true
containsAll(a, b); //false
containsAll(c, b); //false

Where containsAll is a function that checks to see if there is a second parameter inside the first parameter !!! I do not want to convert int arrays to Integer arrays in order to use the following method:

Arrays.asList(a).containsAll(Arrays.asList(b))

Because I think that if the arrays are huge, it will be a big waste of performance !!! But maybe I'm wrong, and the best solution is that ... Do you have an idea?

+4
source share
1 answer

containsAll() Java , ArrayList<Integer> Integer[] Arrays.asList() containsAll().

int[], , .

(, , , ), , .

+1

Source: https://habr.com/ru/post/1686824/


All Articles