Given that 2 strings:
String stringA = "WHATSUP";
String stringB = "HATS";
I want to find out whether each character in stringB H
A
T
S
exists in stringA
In a junior approach, the process can be done within a nested for-loop which its computation complexity is O(n^2).
for(int i = 0; i < stringA.length(); i++){
for(int j = 0; j < stringB.length(); j++){
if(stringA.charAt(i) == stringB.charAt(j))
//do something
}
}
I am looking for a faster solution to solve this problem.
containsAll
– Exoergic