Reputation: 1301
Essentially, I want to have a method:
public void setArgs(String... vals)
{
for (String s: vals)
// Here I can add s every string passed to an array list
The thing I'm wondering is: can I simply store all of the arguments passed to setArgs
in an Array, instead of bothering with an ArrayList
? I know arrays are immutable in java, so I was wondering if you can somehow there's an easy way to extract the arguments without using a loop
.
Thanks.
Upvotes: 1
Views: 546
Reputation: 122008
Yes, Using Arrays class asList() method
List<String> argsList= new ArrayList<String>(Arrays.asList(vals));
Upvotes: 8