So I have a code which generates all possible strings of a length n (currently 5 in this example) with characters in a list "chars" and executes a certain code once on each string in the end (not included here). How would I condense the code here into code that automatically nests the loops n amount of times and then executes a final code on each result?
for(String str2: chars) {
str2 = str1 + str2;
for(String str3: chars) {
str3 = str2 + str3;
for(String str4: chars) {
str4 = str3 + str4;
for(String str5: chars) {
str5 = str4 + str5;
for(String str6: chars) {
str6 = str5 + str6;
}
}
}
}
}
}