Array of args parameters in Java

The args parameter of the main method is used to receive the parameters input by the user, and the parameters are stored in an array in the form of strings. There are two forms of passing parameters here, one is to pass ordinary parameters, and the other is to pass parameters with spaces.

1. Pass common parameters

public class Test {
       public static void main(String[] args) {
        for(String s : args){
            System.out.println(s);
        }
    }
}

pass normal parameters
The main method receives parameters with a space as a delimiter for the parameter, the first parameter is "Hello", and the second parameter is "Word".

2. Pass parameters with spaces

Since the main method accepts parameters with spaces as the delimiter of the parameters, how to distinguish when a parameter is entered with spaces? In fact, we can use double quotes to bind parameters with spaces together.

Pass parameters with spaces

Associated blog (blog garden):

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325981329&siteId=291194637