I have some code
public class NameGenerator {
public static void main (String[] args)
{
List<String> result = new ArrayList<String>();
buildNameChoices("von.del.smith", result);
System.out.println(result);
}
public static void buildNameChoicesHelper(String[] nameArray, int nameIndex,
String firstName, String lastName, List<String> result) {
if(nameIndex >= nameArray.length) {
if(lastName.length() > 0) {
result.add(firstName + lastName);
}
}
else {
System.out.println("Calling first buildNameChoices");
buildNameChoicesHelper(nameArray, nameIndex + 1,firstName, lastName, result);
System.out.println("Calling second buildNameChoices");
buildNameChoicesHelper(nameArray, nameIndex + 1,firstName, lastName + "." + nameArray[nameIndex], result);
}
}
public static void buildNameChoices(String nameStr, List<String> result) {
String[] nameArray = nameStr.split("\\.", -1);
for(int i = 0; i < nameArray.length; i++) {
System.out.println("Inside for loop");
buildNameChoicesHelper(nameArray, i + 1, nameArray[i], "", result);
}
}
}
that generates all possible combinations of a name string that it is passed. The code works, and I understand how the recursion works on some level, but the double recursive call is really confusing me. I've been looking at it for quite some time, and I'm having trouble grasping exactly what it's doing. Any help on this would be greatly appreciated. I've tried debugging through it, but I'm still not really able to understand it.