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);
}
}
}
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.
Associated blog (blog garden):