Answer the question
In order to leave comments, you need to log in
How to determine if an array of strings is contained within another array of strings?
There is a first array
of strings:
And a second one: all elements of st2 are in st1
String[] st1 = {"I", "am", "Bob"};
String[] st2 = {"I", "Bo"};
Answer the question
In order to leave comments, you need to log in
private static boolean containsAll(String[] substr, String[] str) {
for (String s : substr) {
if (!Arrays.toString(str).contains(s)) {
return false;
}
}
return true;
}
You need to go through each element from the second array and find out if it is contained in the first array.
If all are contained, return true, if at least one was not found, return false.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question