Java Design Pattern
Introduction to Java 10
Introduction to Java 11
Introduction to Java 12

Java Command Line Argument

The command line argument is the argument passed to a program at the time of execution. To access the command-line argument inside a java program is quite easy, they are stored as string in String array passed to the args parameter of main() method.

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

40
50
60

Let's see another example:

Example:
class Test10
{
	public static void main(String[] args)
	{
		String[] argh={"x","y","z"};
		args=argh;
		for(String s:args)
		{
			System.out.println(s);
		}
	}
}
Output

1st Run:
java Test10 A B C
X
Y

2nd Run:
Java Test10 A B
X
Y
Z

3rd Run:
Java Test10 A
X
Y
Z

About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.


We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc






 PreviousNext