Consider a Class DataHolder
Attributes:
- Name: data name
- Value: value (comma separated)
My input is a list of DataHolders. eg:
List of DataHolder:
DataHolder1: name:A, value:1,2DataHolder2: name:B, value:X
DataHolder3: name:C, value:a,b,c
I want to build a list of strings like this from the data: 1Xa 1Xb 1Xc 2Xa 2Xb 2Xc
I came up with a logic using reccursion.
void formString(List<DataHolder> dataHolders, int currentIndex, String formedString, int size){
if(currentIndex == size){
// store formedString in a list and return
}
else{
1. get value from dataholder
2. String tokenize the value
3. iterate over the tokenized value and for each tokenized value call
formString(dataHolders, currentIndex + 1, formedString + tokeizedValue,
size)
}
}
My code works and it produces the expected output. 1Xa 1Xb 1Xc 2Xa 2Xb 2Xc
is there a better way to do this other than the recursive method?