Say you have a List
of Strings
or whatever, and you want to produce another List
which will contain every possible combination of two strings
from the original list
(concated together), is there any more efficient way to do this other than using a nested for
loop to combine the String with all the others?
Some sample code:
for(String s: bytes) {
for(String a: bytes) {
if(!(bytes.indexOf(a) == bytes.indexOf(s))) {
if(s.concat(a).length() == targetLength) {
String combination = s.concat(a);
validSolutions.add(combination);
}
}
}
}
The time for execution gets pretty bad pretty quickly as the size of the original list
of Strings
grows.
Any more efficient way to do this?