Array string objects called args
Using Arrays and Collections
When we execute this code, we get the following output:
Length of arr2: 5
changeArray |
|
|
|
||||||
---|---|---|---|---|---|---|---|---|---|
main | main | ||||||||
Before allocation of |
|
||||||||
new array |
|
The length property of a Java array will tell us how many command-line arguments were used. The first argument of the array will contain the first command-line parameter. The second will contain the second command-line parameter, and so forth.
The following CommandLineDemo application illustrates the use of the args array:
System.out.println("\tArgument Number " + i +
": " + args[i]);
java CommandLineDemo /D 1024 /f test.dat
The output of the program would appear as follows:
Argument Number 3: test.dat
[ 139 ]