Isn't the main (String args []) dynamic array?

I know that in public static void main(String args[]) argsis an array that will store command line arguments. But since command line arguments are passed at runtime, is an array args[]a dynamic array? In Java, we know that ArrayList is used to do this kind of job, and how does a simple array object store these arguments at runtime?

+4
source share
4 answers

Java arrays can have their size determined at runtime, and not just compilation time (as opposed to arrays allocated by the C stack). However, the size of the array cannot be changed after its creation.

, . :

    int argCount = 5;
    // ...
    String test[] = new String[argCount];

An ArrayList .

+3

. , , , , , main.

+3

, , , . ; , globing, ( ) , ( ). ( JVM).

+1

Why do you think the args array should be dynamic? The Java virtual machine simply calls the main method and passes the command line arguments as an array of String. There is no more β€œmagic" behind it!

0
source

All Articles