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
Discussions

java - What is args ? and When would you use args? - Stack Overflow
If you're referring to the argument in your main function, these are the command line arguments. You can do with them whatever you like: docs.oracle.com/javase/tutorial/essential/environment/… ... Save this answer. ... Show activity on this post. args is a name of a String array. More on stackoverflow.com
🌐 stackoverflow.com
[General/Java] What is the difference between a argument and a parameter?
Not Java specific, but: Parameters are part of the function signature, whereas arguments are passed to the function. So in the example: int add(int a, int b) { return a + b; } int temp = 42; add(temp, 12); ... the variables a and b are parameters (part of the function) and the variable temp and value 12 are arguments. Generally, the terms are used loosely. The Java main(String[] arg) has a String[] parameter because it can receive information from the caller. Generally, these are command line arguments such as java MyClass optionA optionB. The optionA and optionB will be passed to your Java program as arguments to main. More on reddit.com
🌐 r/learnprogramming
7
5
January 5, 2014
Difference between (String args[]) and (String[] args) in java
Technically, there is no difference. Yet, all the Java Style Guides recommend making the array brackets part of the type. So, the Java correct version according to the conventions is: String[] args. More on reddit.com
🌐 r/learnprogramming
3
1
October 3, 2022
What is the parameter in the main(String[] args) anyway?
Its the arguments you add to the application. For example java main test1 test2 More on reddit.com
🌐 r/learnjava
15
20
July 20, 2019
🌐
GeeksforGeeks
geeksforgeeks.org › java › command-line-arguments-in-java
Command Line Arguments in Java - GeeksforGeeks
Explanation: When the program is executed using java Hello Geeks at GeeksforGeeks, the JVM stores the three command-line arguments in the args array as args[0] = "Geeks", args[1] = "at", and args[2] = "GeeksforGeeks".
Published: September 28, 2026
🌐
Scaler
scaler.com › home › topics › what is string args[ ] in java?
What is String args[] in Java? - Scaler Topics
May 21, 2024 - String[] args is an array of a sequence of strings that are passed to the main function. Learn more String args array on Scaler Topics.
🌐
Stack Overflow
stackoverflow.com › questions › 38328221 › what-is-args-and-when-would-you-use-args
java - What is args ? and When would you use args? - Stack Overflow
You can do with them whatever you like: docs.oracle.com/javase/tutorial/essential/environment/… ... Save this answer. ... Show activity on this post. args is a name of a String array.
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › environment › cmdLineArgs.html
Command-Line Arguments (The Java™ Tutorials > Essential Java Classes > The Platform Environment)
A Java application can accept any number of arguments from the command line. This allows the user to specify configuration information when the application is launched.
🌐
W3Schools
w3schools.com › java › java_methods_param.asp
Java Method Parameters
Information can be passed to methods as a parameter. Parameters act as variables inside the method.
Find elsewhere
🌐
Quora
quora.com › Whats-the-purpose-of-args-in-the-main-method-in-Java-programming
What's the purpose of 'args' in the main method in Java programming? - Quora
Answer (1 of 7): The (String args[]) is for passing String parameters to the main method when the Java class file is executed from the command line interface. The parameters passed during the command line execution are all caught in the String array args. Consider a class Test.java: public clas...
🌐
DEV Community
dev.to › manoj_k_ › parameters-and-arguments-in-java-2ljn
Parameters and arguments in java - DEV Community
September 14, 2025 - Arguments Arguments are the actual values or data that you pass to a method when calling...
🌐
Medium
medium.com › @VictoriousAura › oh-whats-this-in-public-static-void-main-string-args-in-java-d22318fc5455
Oh! Whats this ‘…’ in public static void main(String … args) in Java? | by Shrreya Behll | Medium
January 13, 2019 - Varargs or Variadic function in Java was introduced as a language feature in J2SE 5.0. The argument of the method can be declared as a variable arity parameter or simply varargs method.
🌐
GoLinuxCloud
golinuxcloud.com › home › programming › java › java arguments explained [easy examples]
Java Arguments Explained [Easy Examples] | GoLinuxCloud
September 29, 2021 - As we already discussed Arguments in Java are the actual values that are passed to variables defined in the method header when the method is called from another method. That is, whenever any particular method is called during the execution of ...
🌐
Augustana University
lovelace.augustana.edu › q2a › index.php › 522 › what-does-args-do
What does args do? - Augustana CSC Q&A
November 15, 2018 - In the "public static void main (String [] args) {" line, what does the word args do and why is it necessary?
🌐
Blogger
javarevisited.blogspot.com › 2013 › 04 › what-is-string-args-in-java-main-method.html
What is String args[] Argument in Java Main method? Example
When we start a Java program, JVM loads class with main method and pass String array, which contains arguments from command line. You can use this string array to control behavior of your Java program by passing arguments.
🌐
Medium
ahedbahri.medium.com › what-is-the-use-of-args-in-java-95a15c180e8c
What is the use of args in Java?. The interesting use of args in Java. | by Ahed Bahri | Medium
February 27, 2020 - The interesting use of args in Java. The meaning of each word ! args[ ] is an array of string objects, yep you already read that on top !
🌐
Codemia
codemia.io › home › knowledge hub › what is the string args[] parameter in the main method?
What is the String args[] parameter in the main method? | Codemia
January 26, 2025 - Therefore, if you run a Java program from a command prompt or terminal, any space-separated values appearing after the class name are passed to the main method and can be utilized by the program. The args parameter operates as an array of strings, where each element in the array is a command-line argument.
🌐
Quora
quora.com › What-is-the-meaning-of-args
What is the meaning of args? - Quora
Answer (1 of 5): The word “args” in C/C++/Java/whatever is a programmers idea of an abbreviation. A typical program in C demonstrates this: [code]#include int main( int argc, char *argv[] ) { printf("No. of args: %d\n", argc ); } [/code]It is clear in this example that “args” means...
🌐
Quora
quora.com › What-does-the-String-args-in-a-Java-main-method-actually-mean
What does the 'String[ ] args' in a Java main method actually mean? - Quora
Answer (1 of 21): String[] args in Java is an array of strings which stores arguments passed by command line while starting a program. All the command line arguments are stored in that array. Following example will clear your doubt: [code]public class Test { public static void main(String[] ...
🌐
CodeGym
codegym.cc › java blog › core java › java command line arguments
Java command line arguments
February 14, 2025 - The command line arguments in java are the arguments passed to the program from the console. The command line argument in java is the information passed to the program at the time of running the program.
🌐
Centron
centron.de › startseite › how to work with command-line arguments in java
Command-Line Arguments in Java: A Beginner's Guide
February 7, 2025 - Command-line arguments are an essential aspect of programming in Java, allowing parameters to be passed directly to the main program. These arguments are treated as strings and provide a dynamic way to interact with applications during runtime.