How do I pass an ArrayList to a method expecting a vararg (Object...)?
<p>Assume a method with the following signature:</p>

<pre><code>public static void foo(String arg1, String args2, Object... moreArgs);
</code></pre>

<p>When running ...</p>

<pre><code>ClassName.foo("something", "something, "first", "second", "third");
</code></pre>

<p>... I'll get <code>moreArgs[0] == "first"</code>, <code>moreArgs[1] == "second"</code> and <code>moreArgs[2] == "third"</code>.</p>

<p>But assume that I have the parameters stored in an <code>ArrayList&lt;String&gt;</code> called <code>arrayList</code> which contains "first", "second" and "third".</p>

<p>I want to call <code>foo</code> so that <code>moreArgs[0] == "first"</code>, <code>moreArgs[1] == "second"</code> and <code>moreArgs[2] == "third"</code> using the <code>arrayList</code> as a parameter.</p>

<p>My naïve attempt was ...</p>

<pre><code>ClassName.foo("something", "something", arrayList);
</code></pre>

<p>... but that will give me <code>moreArgs[0] == arrayList</code> which is not what I wanted.</p>

<p>What is the correct way to pass <code>arrayList</code> to the <code>foo</code> method above so that <code>moreArgs[0] == "first"</code>, <code>moreArgs[1] == "second"</code> and <code>moreArgs[2] == "third"</code>?</p>

<p>Please note that the number of arguments in <code>arrayList</code> happens to be three in this specific case, but the solution I'm looking for should obviously be general and work for any number of arguments in <code>arrayList</code>. </p>
