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.
ArrayListinstead?Arrays.asList()at all in this situation, I would do exactly what is being done in the accepted answer, add directly to a new list in your loop, if you actually need the concatenation of zeros for something else, build that later, from the list.