I need to create a function that returns a number with the amount of characters in common among one string and a vector of them.
public int sameChars (Vector<String> otherStrs){
int result = 0;
String original = "aab";
for (int i=0; i< original.length(); i++) {
char aux = original.charAt(i);
String targetStr = otherStrs.get(i);
for (int j=0; j< targetStr.length(); j++) {
char targetAux = targetStr.charAt(j);
if (aux.compareTo(targetAux) == 0) {
result++;
}
}
}
return result;
}
3 problems in this initial stage:
- Getting error on compareTo, char cannot be dereferenced.
- I need to distinguish 'A' from 'a'. Equals doesnt do it.
- I need to account only for 1 of each character type. ("aab" compared to "ababababba" should only give a total count of 2.
Help is appreciatted to the newbie :)