Use the apache commons cli if you plan on extending that past a single arg.

"The Apache Commons CLI library provides an API for parsing command line options passed to programs. It's also able to print help messages detailing the options available for a command line tool."

Commons CLI supports different types of options:

  • POSIX like options (ie. tar -zxvf foo.tar.gz)
  • GNU like long options (ie. du --human-readable --max-depth=1)
  • Java like properties (ie. java -Djava.awt.headless=true -Djava.net.useSystemProxies=true Foo)
  • Short options with value attached (ie. gcc -O2 foo.c)
  • long options with single hyphen (ie. ant -projecthelp)
Answer from John Ellinwood on Stack Overflow
🌐
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
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › environment › cmdLineArgs.html
Command-Line Arguments (The Java™ Tutorials > Essential Java Classes > The Platform Environment)
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.
Discussions

Java Command line arguments - Stack Overflow
I am trying to detect whether the 'a' was entered as the first string argument. More on stackoverflow.com
🌐 stackoverflow.com
How do I put a command-line argument when running from an IDE
Go to Run -> Edit Configurations... and look at your run configuration. There is a field for "Program arguments". More on reddit.com
🌐 r/java
3
0
May 6, 2014
What’s the use of doing command line argument in Java?
If you'd like the user to be able to provide different "options" to your program, you can use command-line arguments. For example: Perhaps your program has different "modes" of some kind Perhaps your program reads from a file, and you'd like to be able to pass in different filenames You could also prompt the user for input once the program is running, but sometimes this is not convenient. More on reddit.com
🌐 r/learnjava
3
1
August 1, 2020
Is there a static method to get command-line arguments?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
10
2
February 27, 2024
🌐
Baeldung
baeldung.com › home › java › core java › command-line arguments in java
Command-Line Arguments in Java | Baeldung
September 16, 2026 - The code above expects the file path as a command-line argument. If no file path is provided, it throws an exception and prints the usage instructions instead of attempting to read the file. Let’s place a file named hello.txt in our resources folder and pass its absolute path as an argument in our IDE run configuration: "/home/baeldung/tutorials/core-java-modules/core-java-lang/src/main/resources/hello.txt"
🌐
Programiz
programiz.com › java-programming › command-line-arguments
Java Command-Line Arguments | Programiz
March 13, 2024 - The String array stores all the arguments passed through the command line. Note: Arguments are always stored as strings and always separated by white-space. The main() method of every Java program only accepts string arguments.
🌐
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 ...
🌐
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
🌐
Princeton
cs.princeton.edu › courses › archive › spr96 › cs333 › java › tutorial › java › cmdLineArgs › index.html
Command Line Arguments
Your Java application can accept any number of arguments from the command line. Command line arguments allow the user to affect the operation of an application.
Find elsewhere
🌐
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 · int firstArg; if (args.length > 0) { try { firstArg ...
🌐
TechVidvan
techvidvan.com › tutorials › java-command-line-arguments
Java Command Line Arguments with Examples - TechVidvan
April 9, 2020 - The data in command-line arguments are in the form of String. This brings us to the end of the article on Java Command line arguments.
🌐
Sde-coursepack
sde-coursepack.github.io › modules › java › Command-Line-Arguments
SDE | Command Line Arguments
java myPackage.myClassName these are my lovely arguments ... Reminder that when we want to run class files from command line, we need to include the package name.
🌐
Coding Shuttle
codingshuttle.com › home › handbooks › java programming handbook › java commandline arguments
Java CommandLine Arguments | Coding Shuttle
April 9, 2025 - Java allows us to pass arguments to the main() method when running a program from the command line.
🌐
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.
🌐
Codemistic
codemistic.github.io › java › command-line-arguments-java.html
Command-Line Arguments in Java| Java Tutorials | CodeMistic
Command Line Argument in Java is the information that is passed to the program when it is executed. The information passed is stored in the string array passed to the main() method and it is stored as a string. It is the information that directly follows the program’s name on the command ...
🌐
Medium
medium.com › @AlexanderObregon › processing-command-line-arguments-in-java-applications-200ba9b7f029
Processing Command-Line Arguments in Java Applications
March 14, 2025 - Java captures these arguments using the args[] array inside the main method. Command-line arguments are passed as space-separated values when executing a Java program.
🌐
CodeGym
codegym.cc › java blog › core java › java command line arguments
Java command line arguments
February 14, 2025 - The command line argument in java is the information passed to the program at the time of running the program. It is the argument passed through the console when the program is run.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › command line arguments in java
Command Line Arguments in Java Explained with Examples
August 31, 2026 - This concept not only enhances flexibility but also helps in customizing application behavior without changing the source code. ... In Java, command line arguments are the values passed to the main() method when a program is launched.
🌐
javathinking
javathinking.com › blog › command-line-arguments-in-java
Command-Line Arguments in Java: A Comprehensive Guide — javathinking.com
When you run a Java program from the terminal (e.g., java MyApp arg1 arg2), the strings arg1 and arg2 are command-line arguments.
🌐
HackerNoon
hackernoon.com › command-line-arguments-in-java-for-beginners-p21233y9
Command-Line Arguments In Java For Beginners | HackerNoon
April 3, 2021 - Java command line arguments are arguments that are passed to your program via a terminal or shell command.