Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a "vararg" method with an array of params?

I'm trying to call String.format() having a String and Object[]. How can I do it?

like image 944
yegor256 Avatar asked Nov 05 '10 15:11

yegor256


People also ask

Can I pass array to Varargs?

There are multiple ways of converting a Kotlin array to a vararg parameter. Firstly, we can simply pass an array with a spread operator to the function call. It's also possible to pass multiple arrays. Additionally, we can even combine literals and arrays to functions with vararg parameters.

Can I pass array to Varargs Java?

Java static code analysis: Arrays should not be created for varargs parameters.

Is Vararg an array?

As mentioned earlier, varargs are arrays so we need to work with them just like we'd work with a normal array.


1 Answers

Simply like that:

String.format(myString, myArray);
like image 109
Romain Linsolas Avatar answered Nov 15 '22 08:11

Romain Linsolas