I know that in public static void main(String args[])
args
is an array that will store command line arguments. But since command line arguments are passed during runtime, is the array args[]
a dynamic array? In Java we know that an ArrayList is used to accomplish that kind of a job, so how does a simple array object store those arguments at runtime?
Java arrays can have their size defined at runtime, not just compile time (unlike C stack allocated arrays). However, the size of an array cannot be changed once it has been created.
It is perfectly valid to have an array created at runtime. It is not possible to change the size after it has been created though:
int argCount = 5;
// ...
String test[] = new String[argCount];
An ArrayList
lets you grow and shrink the size of the underlying list at runtime.
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