0

Some function in java using variable length parameter. like

String java.lang.String.format(String format, Object... args)

How can dynamically pass parameter to this function?

For example

String fillInString(String str, ArrayList<String> token){
    return String.format(str, token[0], token[1]....);   
}

2 Answers 2

3
String fillInString(String str, ArrayList<String> token){
    return String.format(str, token.toArray(new String[token.size()]));   
}
Sign up to request clarification or add additional context in comments.

Comments

3

send the token value to the function as an array.

String fillInString(String str, String ... token){
    return String.format(str, token);
}

var args like this can accept seperate arguments or an array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.