Well in that case, the only one-size solution is to keep an "active" list of names which haven't been matched yet and then for each search, iterate through the entire active list and only match if it finds a unique match with exactly one entry in the active list.
public void uniqueContainsMatch(String[] set1, String[] set2) {
List<String> searching = Arrays.asList(set1);
List<String> active = Arrays.asList(set2);
int i = -1;
int itersSinceLastChange = 0;
while(!searching.isEmpty()) {
if(itersSinceLastChange > searching.size()) {
//Then you have gone through the whole list and not matched anything.
//Hence a unique match isn't possible.
//If you can be bothered you'd handle this properly
throw new RuntimeException("Unique Match Not Possible");
}
if(i >= searching.size()) {
i = 0;
}
int match = -1;
for(int j = 0; j < active.size(); j++) {
if(active.get(j).contains(searching.get(i))) {
if(match == -1) {
match = j;
} else {
match = -1; //Since not unique match
break;
}
}
}
if(match != -1) {
itersSinceLastChange = 0;
String s1 = searching.remove(i);
String s2 = active.remove(match);
//Then you've got a bingo. Handle here.
} else {
itersSinceLastChange++;
i++;
}
}
}
Disclaimer: this code is not tested and it is the kind of sort of complicated code I normally make mistakes in but it should get the idea across. It is also not the prettiest code I've ever written but it should get the idea across. It is also not the most efficient code I've ever written but it should get the idea across.