tejas
tejas

Reputation: 67

Pass multiple values for single string argument

I am working on a framework which is already created in Selenium. It is a keyword driven framework. All keyword takes single data value as a argument. How can I pass multiple values for that single string argument in keyword. Keyword has only single string argument.

Upvotes: 2

Views: 4201

Answers (2)

David Webb
David Webb

Reputation: 193706

If you want to change the signature of your methods to accept multiple keywords you can use varargs to keep backwards compatibility with your existing code.

So change:

public void someMethod(String keyword) {
   //keyword is a String
}

to

public void someMethod(String... keywords) {
   //keywords is a String[]
}

When someMethod is called with a single argument keywords is a String array of length 1.

Upvotes: 0

anubhava
anubhava

Reputation: 785146

If you don't have any argument other that single String then you can pass delimited string to that method e.g.

val1,val2,val3

and then inside the method use String#split to split the passed String into array or List.

PS: Just make sure that chosen delimiter doesn't appear inside the string values.

Upvotes: 3

Related Questions