I'm trying to call String.format()
having a String
and Object[]
. How can I do it?
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.
Java static code analysis: Arrays should not be created for varargs parameters.
As mentioned earlier, varargs are arrays so we need to work with them just like we'd work with a normal array.
Simply like that:
String.format(myString, myArray);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With