java passed variable parameters

When calling a method, you must pass the specified parameters depending on the type of parameter, after JDK1.5, the introduction of the concept of variable parameters, that we may need to pass parameters as needed.

How to pass:

The method return type name (parameter type name ...)

Examples

Output transmission parameter

    @Test
    public void getArgs(){
        foo();
        foo("1","2");
        foo("1","2","3");
    }

    public static void foo(String ...strs){
        for (String s : strs){
            System.out.print(s+"、");
        }
        System.out.println("");
    }

operation result:

1,
2, 3,
the first parameter is not passed.

Published 22 original articles · won praise 9 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_19408473/article/details/70920062