Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Convert Array to Parameters

Is there a way to convert an array to a list of 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
}

I want to convert "a" into a parameter/argument list so it will automatically call the appropriate function.

like image 348
Ying Chan Avatar asked Oct 22 '10 04:10

Ying Chan


1 Answers

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

void MyPrint(int... x){
//Do Stuff to arguments (accessing them by its index)
}
like image 73
Cristian Avatar answered Sep 30 '22 20:09

Cristian