Processing Java Command Line Arguments

This is the typical format for declaring the main program
    public static void main (String[] args) {
This declares that there is an array of Strings that is named args.
The number of Strings that are in args can be found by using the length property.
    int argc = args.length;

    System.out.println("There are " + argc + " command line arguments:");

    Note: Arrays are indexed beginning with 0, so an array that has three elements will use index [0], [1], and [2].

Here is a complete program that will print out a list of command line arguments, one per line:
public class echo2 {
    public static void main (String[] args) {

        String s="";
	int    argc = args.length;

	System.out.println("There are " + argc + " command line arguments:");
	
        for (int i = 0; i< argc; i++) {
            System.out.println("Argument #" + i + ": " + args[i]);
            }
    }
}
    The program named echo2 is compiled in the usual way
      javac echo2.java

    The program can be run without passing in any command line arguments
      java echo2
      Program output:
      There are 0 command line arguments:

    The progam can be run with any other number of command line arguments
      java echo2 parameter1 parameter2 parameter3
      Program output:
      There are 3 command line arguments:
      Argument #0: parameter1
      Argument #1: parameter2
      Argument #2: parameter3
    Another example running with any number of command line arguments
      java echo2 these are command line arguments
      Program output:
      There are 5 command line arguments:
      Argument #0: these
      Argument #1: are
      Argument #2: command
      Argument #3: line
      Argument #4: arguments
    Multi-word arguments can be passed by using quotes
      java echo2 "these are command line arguments"
      Program output:
      There are 1 command line arguments:
      Argument #0: these are command line arguments
In some languages there is a "foreach" loop that will process all elements of a collection. In java a similar for loop can be used. In the example below a String variable s is declared and then used to process each member of the args array. This example has the same functionality as the echo2 program above.
Source: The javaTMTutorials at Oracle.com.
public class echo {
    public static void main (String[] args) {
        for (String s: args) {
            System.out.println(s);
        }
    }
}