How can I set size of a dynamic array with Java?
I tried setsize(...)
with the array variable but not working.
How can I do this?
array size needs to be fixed while initialization, use List
instead and then have array from List
using toArray()
For example:
List<Integer> listOfInt = new ArrayList<Integer>(); //no fixed size mentioned
listOfInt .add(1);
listOfInt .add(2);
listOfInt .add(3);
//now convert it to array
Integer[] arrayOfInt = list.toArray(new Integer[listOfInt .size()]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With