[Java] variable argument list

public class T2 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String strs[] = {"I", "am", "CHX" };
		test(1, strs);
		System.out.println("");
		test1(strs, 0);
	}
	public static void test(int i, String...strs) {
		System.out.println("i = "+i);
		for (String str : strs) {
			System.out.print(str);
		}
	}
	public static void test1 (String [] strs, int i) {
		System.out.println("i = "+i);
		for(String str : strs) {
			System.out.print(str);
		}
	}
}

operation result:

Note that variable argument list to put the end of the parameter list, but variable parameter list is essentially an array of syntactic sugar packaging

... can be used instead of an array of variable argument lists written, then the parameter list can be placed anywhere parameters

A method can have only one variable parameter list, but can have multiple array parameters

Put the top two variable parameter lists, error

Guess you like

Origin blog.csdn.net/chenhanxuan1999/article/details/91377820