Home > Software engineering >  How do I split a list to stringS (plural)
How do I split a list to stringS (plural)

Time:10-18

I have a list of strings of dynamic length: List<String> processInstanceIds = new ArrayList<>();

I have a function that doesn't accept a list as parameter, but requires one to several individual strings:

function

How can I transform this list of dynamic length to a dynamic amount of strings and pass them to the function?

myfunction(String.join(", ", theList)) did not work as it would create one string instead of several.

CodePudding user response:

Java varargs creates a method array parameter. Try something like this:

String[] blam = yourList.toArray(processInstanceIds);

kapow.myFunction(blam);

CodePudding user response:

Probably, you could try something like below

processInstanceIds.toArray(new String[processInstanceIds.size()])
  •  Tags:  
  • java
  • Related