Java: init array -- but don't know size

how do I decl/init an array of strings in Java when I don’t know the size of it (it’s coming from request… not from a form… it’s sent from ajax…)

thank you…

One thing you could do is create an array with a fixed size, and then keep track of how full it is and once it’s full create a new array of twice the size, copy all elements to the new array, and then use that one, etc. But of course this is kind of messy.
Another thing you could do is use List or ArrayList instead, which will just grow when needed (basically doing what I’ve described above, under the hood)

Also see

actually I mananged to create an array fine w/o knowing its size, thus:

        String[] testArr;

        testArr = new String[] {"red","green","blue","pink"};

but the thing is (do I need to create a new thread for this other question?), I actually need to grab the array from the request, that I send with ajax (jQuery) thus:

          data: {  namesArray : namesAfterPick }

but can’t seem to grab it with java on the back-end… this

	namesArr = request.getParameterValues("namesArray");

is not grabbing it…

(for grabbing a single string, this

nameChosen = request.getParamater("namePicked");

works fine when sending thus:

          namePicked: names[0]

thank you…