I was asked to write down a Java function sharedStr that by given 2 sorted arrays of Strings, returns the number of Strings that appea
First, the second part of your question:
Comparing strings in Java isn't as simple as:
if(sStringOne == sStringTwo)
//Equal
you should instead use methods of the string class
if(sStringOne.equals(sStringTwo)
// Equal
Second, the first part of your question:
Yes, it would be easy to loop through the first array and count each indexs occurence in the second array. Since you've specified each array must be iterated only once however, perhaps the following algorithm may suit: