What Is The “String args[]” Parameter In The Main Method?

Today we will Learn What Is The “String args[]” Parameter In The Main Method? where it is a string type array which is used for storing the command line arguments in the form of strings. And args is the name of that string array and the name we can keep as per our requirement.

String

String args[] Statement

args is the name of a variable of an array of type strings which is created to store the command line arguments in the form of string and we can change the name of the variable.

Moreover, we can use it as String[] args means we can use the square brackets before the variable name. Ans it is designed in such a way that when the main function is called it must have an argument as a string array to call and it is called in such a way.

And as the main function is called the primary function in java and it is called on it own as it is a static function that does not require any call to be called and get executed.

Let’s understand what is discussed with an example here

class GeeksforGeeks {
   
      // Commamd-Line Code ->
    // javac GeeksforGeeks.java
    // java GeeksforGeeks 1 2 3
   
    public static void main(String[] args)
    {
        for (String elem : args)
            System.out.println(elem);
    }
}

The above code will result in 1, 2, 3, and 4 as it will print the elements stored in the args array. All these are stored on calling the function.

 

Learn more about What Is The “String args[]” Parameter In The Main Method and all other components of main functions at Public Static Void Main(String[] args)

And also visit Java Tutorials to learn and solve problems faced in java during learning core java along with it you can also visit Python’s list: What is the difference Between methods Append and Extend? To learn more about python and here you can learn more about different programming languages.

 

Leave a Comment

%d bloggers like this: