I am all new here and also a beginner. I am working on a personal project (developing an app for personal use). I am a bit stuck and yes, I did search around but couldn't find much.
My aim is to find all possible combinations. Let's say I have a finite number of lists defined like:
List AList contains {"a1","a2","a3","a4"}
List BList contains {"b1","b2","b3"}
List CList contains {"c1","c2","c3","c4","c5"}
List DList contains {"d1","d2"}
I would like to find all combinations with:
1) the combination a1 a2 vein the same as a2 a1 and so on
2) the number of elements per result set not being fixed: a combination possibility is per example merging all lists into one.. or each element in a list of its own or merging two elements in a list and the rest in another.. and so on..
I know it has to be a recursive function.. but that how far i am right now.. Any help would be appreciated. Thanks
解决方案
i did a similar thing for myself, this however would give you permutations of a1 a2 etc and not combinations, meaning the order does not matter.
public void permutation(String prefix, String str) {
int n = str.length();
if (n==0){}
else {
for (int i = 0; i < n; i++)
permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));
}
}
With this logic, you would have to turn your Lists into one long string and then send this method your string