JDK5之后版本新增了可变参数的新特性:
package com.example.revian; import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class ArrayTest { @Test public void test() { String[] excludes = new String[]{"/login", "/register"}; printArgs(excludes); System.out.println("================"); printArgs("/login", "/register"); } private void printArgs(String... excludes) { List<String> list1 = new ArrayList<>(Arrays.asList(excludes)); list1.forEach(System.out::println); } }