Java将数组转换为参数

Yin*_*han 8 java parameters

有没有办法将数组转换为参数列表..?

main(){
   //"a" is an array or a list or some collection
   myPrint(a.SomeMethod);
}

void myPrint(int a){
//Do Stuff to arguments
}

void myPrint(int a, int b){
//Do Stuff to arguments
}

void myPrint(int a, int b, int c){
//Do Stuff to arguments
}
Run Code Online (Sandbox Code Playgroud)

我想将"a"转换为参数/参数列表,以便它自动调用相应的函数.

Cri*_*ian 8

main(){
   int[] a = {1,2,3};
   MyPrint(a);
}

void MyPrint(int... x){
//Do Stuff to arguments (accessing them by its index)
}
Run Code Online (Sandbox Code Playgroud)