Try to use ArrayList
instead of String concatenation.
List<String> responseListSize = new ArrayList<String>(countOptions);
for(int i = 0; i < countOptions; i++){
responseListSize.add( addResponseTuple );
}
Question
I need to make the size of a list fixed dynamic but dynamic based on the parameters of its initiation.
I am trying the following -
int countOptions = countOptions(s_sqlContext, s_organisationId);
String responseListSize = "\"0\"";
String addResponseTuple = ",\"0\"";
for (int i = 1; i < countOptions; i++) {
responseListSize = responseListSize.concat(addResponseTuple);
}
List<String> ret = Arrays.asList(new String[] { responseListSize });
countOptions
returns an integer that may be 10 for one person or 3 for another. This obviously does not work because it is setting ret
as a single index List of "0","0","0","0"
(if countOptions is 4), when I need each "0"
to have its own index.
I hope this all makes sense, and I really hope it is possible.
Solution
Try to use ArrayList
instead of String concatenation.
List<String> responseListSize = new ArrayList<String>(countOptions);
for(int i = 0; i < countOptions; i++){
responseListSize.add( addResponseTuple );
}