In Java args contains the supplied command-line arguments as an array of String objects.

In other words, if you run your program in your terminal as :

C:/ java MyProgram one two

then args will contain ["one", "two"].

If you wanted to output the contents of args, you can just loop through them like this...

public class ArgumentExample {
    public static void main(String[] args) {
        for(int i = 0; i < args.length; i++) {
            System.out.println(args[i]);
        }
    }
}

The program will print in the terminal:

C:/ java MyProgram one two
one
two
    
C:/
Answer from Dan Lew on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › command-line-arguments-in-java
Command Line Arguments in Java - GeeksforGeeks
Command-line arguments are passed ... main(String[] args) method. ... Example: In this example, we are going to print a simple argument in the command line....
Published: September 28, 2026
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › environment › cmdLineArgs.html
Command-Line Arguments (The Java™ Tutorials > Essential Java Classes > The Platform Environment)
This allows the user to specify configuration information when the application is launched. The user enters command-line arguments when invoking the application and specifies them after the name of the class to be run. For example, suppose a Java application called Sort sorts lines in a file.
🌐
W3Schools
w3schools.com › java › java_methods_param.asp
Java Method Parameters
When a parameter is passed to the method, it is called an argument. So, from the example above: fname is a parameter, while Liam, Jenny and Anja are arguments.
🌐
Baeldung
baeldung.com › home › java › core java › command-line arguments in java
Command-Line Arguments in Java | Baeldung
September 16, 2026 - For example, a run configuration defines which JVM to use, what is the entry point, the classpath, and so on. And of course, we can specify command-line arguments. The easiest way to create an appropriate run configuration is to right-click ...
🌐
Tutorialspoint
tutorialspoint.com › java › java-command-line-args.htm
Java - Command Line Arguments
Command line arguments allows to configure the application behavior by passing the arguments before start of the application. Batch processes are one of the example where command line arguments are heavily used to execute java commands with configuration parameters.
🌐
Programiz
programiz.com › java-programming › command-line-arguments
Java Command-Line Arguments | Programiz
March 13, 2024 - class Main { public static void main(String[] args) { for(String str: args) { // convert into integer type int argument = Integer.parseInt(str); System.out.println("Argument in integer form: " + argument); } } } Let's try to run the program ...
🌐
Emory
mathcs.emory.edu › ~cheung › Courses › 170 › Syllabus › 09 › command-args.html
Emory
Java program that prints the elements in the parameter variable args: Example Program: (Demo above code) &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp · Prog file: click here ·
Find elsewhere
🌐
Emory
cs.emory.edu › ~cheung › Courses › 170 › Syllabus › 09 › command-args.html
The command line arguments of a Java program
Java program that prints the elements in the parameter variable args: Example Program: (Demo above code) &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp · Prog file: click here ·
🌐
Sde-coursepack
sde-coursepack.github.io › modules › java › Command-Line-Arguments
SDE | Command Line Arguments
Note that you can also have optional arguments with parameters. For example, let’s say instead of -j, I have -c which lets the user specify any one of several calendars (including the Julian), but I still default to Gregorian because it is the most widely used calendar in the world today. At that point, I may have a command lined like: java edu.virginia.cs.commandline.IsLeapYear 1900 -c Julian
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › command line arguments in java
Command Line Arguments in Java Explained with Examples
August 31, 2026 - Command line arguments in Java are values passed to a program when it is run from the terminal or command prompt. They are stored in the String[] args array of the main() method, allowing the program to receive dynamic input at runtime.
🌐
Upgrad
upgrad.com › home › blog › software development › command line arguments in java [with example]
Command Line Arguments in Java [With Example] | upGrad blog
August 11, 2026 - Java programs, you must have noticed the (String[] args) in the main() method. These are command-line arguments being stored in the string passed to the main method.
🌐
Edureka
edureka.co › blog › java-command-line-argument
Java Command Line Arguments With Examples | Java Tutorial | Edureka
August 27, 2024 - The command-line arguments are stored in the String args of the main() method of the program. Related Learning: Java Interview Questions for 3 Years Experience
🌐
TechVidvan
techvidvan.com › tutorials › java-command-line-arguments
Java Command Line Arguments with Examples - TechVidvan
April 9, 2020 - A command-line argument is nothing but the information that we pass after typing the name of the Java program during the program execution.
🌐
Caltech
courses.cms.caltech.edu › cs11 › material › java › donnie › java-main.html
Java Program Invocation and Command-Line Arguments
If a Java program requires numeric command-line arguments, it must explicitly convert the string version of the number into the actual numeric value. With the above example, the first argument is "1234", a String, and it must be converted into an actual integer value.
🌐
GeeksforGeeks
geeksforgeeks.org › java › variable-arguments-varargs-in-java
Variable Arguments (Varargs) in Java - GeeksforGeeks
September 28, 2026 - Varargs were introduced in Java 5 to simplify this process. They allow a method to accept zero or more arguments of the same type using a single parameter. Example: Demonstrating the working of varargs with integer argument
🌐
Medium
medium.com › @AlexanderObregon › processing-command-line-arguments-in-java-applications-200ba9b7f029
Processing Command-Line Arguments in Java Applications
March 14, 2025 - Instead of writing separate versions ... connector might require a URL, username, and password: java DatabaseConnector jdbc:mysql://localhost:3306/mydb user123 pass456...
🌐
CS156
ucsb-cs156.github.io › topics › java › java_command_line_arguments.html
Java: Command Line Arguments | CS156 - GitHub Pages
If you run java Main foo bar fum then args.length is 3, args[0] is "foo", args[1] is "bar", and args[2] is "fum" Command line args come in as Strings. If you want an int, use Integer.parseInt as in this example from Oracle’s tutorial
🌐
javaspring
javaspring.net › blog › what-is-args-in-java
Understanding `args` in Java — javaspring.net
When you run a Java program from the command line, you can provide additional information that the program can use. These additional pieces of information are stored in the args array. For example, if you have a Java program named MyProgram.java and you run it using the following command:
🌐
javathinking
javathinking.com › blog › what-is-the-string-args-parameter-in-the-main-method
What is String args[] in Java's main method? Explained with Examples & Usage — javathinking.com
The [] denotes an array, which allows multiple arguments to be passed. For example, if you run java MyProgram apple banana cherry, args[] will hold ["apple", "banana", "cherry"]—three separate String elements in order.