I have a requirement where I need to pass the items of a list as arguments to a library function. This function receives arguments as String[] args
. So something like myFunc(list[0], list[1], list[2]...)
. Is there a way to just extract the items of a list and pass them?
Specifics:
Code:
CsvSchema schema = csvMapper.typedSchemaFor(PersonDetailsCSVTemplate.class)
.withHeader()
.sortedBy("personNameHeader", "personAgeHeader",...)
.withColumnSeparator(',')
.withComments();
Here the sortedBy function needs multiple strings as arguments based on which it will do the sorting and although I have a list of strings received from csv header row, I am not sure how to pass them individually.
You can convert your
List<String>
to aString[]
with thetoArray(IntFunction<T[]> generator)
method that was added in Java 11:Or to pass it directly:
On Java 8, use the overload of
toArray
that takes an array:Or:
If the array is too small, it will create one of the necessary size, based on the element type of the array you pass in. That is why passing in a zero-length array will work.