Below is the list of Strings i need combinations for with certain conditions.
"MSD" ,"EEE", "RSR", "OCL", "SMS","RTS"
The conditions for the combinations are
- Combinations should be having atleast two string
(E.g : ("EEE"
,"RSR") ,("EEE","RSR","OCL")) - Combinations should be consisting adjacent strings (E.g: ("OCL","SMS"),("MSD","EEE","RSR") are valid. But not ("EEE","OCL"). Since "EEE" and "OCL" are not next to each other)
Java implementation is much welcome for this problem.
public class Dummy {
public static void main(String[] args) {
String[] str = { "MSD" ,"EEE", "RSR", "OCL", "SMS","RTS" };
List<String> list = new ArrayList<>();
for (int j = 0; j < str.length; j++) {
String temp = "";
for (int i = j; i < str.length; i++) {
temp = temp + " " + str[i];
list.add(temp);
}
}
for (String string : list) {
System.out.println(string);
}
}
}
Sorry for the late update of my tried code