Using Command Line Arguments and Variable length arguments(Varargs)

Shubham Dadasaheb Sawant
2 min readJun 16, 2022
  1. Command line argument:

Sometimes you want to pass information into a program when you run it.
This is achieved by passing command line arguments to main(). Command line arguments are stored as strings in a String array passed to args parameter of main().
1. first command line argument args[0]
2. second command line argument args[1] … and so on.

In above snapshot arguments are needed to pass from command line while executing java code as shown above.
In this way arguments are passed to the program and further this arguments can be used as required in the program.

NOTE: all command line arguments are passed as strings. You may convert them manually.

2. Varable length arguments (Var args):

  1. Variable length arguments are very useful when no of args to pass are not known to the programmer.

2. Program

3. Program

Overloading Vararg method:

--

--