title: How to pass an ArrayList to a varargs method parameter?
body: <p>Basically I have an ArrayList of locations:</p>
  
  <pre><code>ArrayList&lt;WorldLocation&gt; locations = new ArrayList&lt;WorldLocation&gt;();
  </code></pre>
  
  <p>below this I call the following method:</p>
  
  <pre><code>.getMap();
  </code></pre>
  
  <p>the parameters in the getMap() method are:  </p>
  
  <pre><code>getMap(WorldLocation... locations)
  </code></pre>
  
  <p>The problem I'm having is I'm not sure how to pass in the WHOLE list of <code>locations</code> into that method.</p>
  
  <p>I've tried</p>
  
  <pre><code>.getMap(locations.toArray())
  </code></pre>
  
  <p>but getMap doesn't accept that because it doesn't accept Objects[].</p>
  
  <p>Now if I use</p>
  
  <pre><code>.getMap(locations.get(0));
  </code></pre>
  
  <p>it will work perfectly... but I need to somehow pass in ALL of the locations... I could of course make keep adding <code>locations.get(1), locations.get(2)</code> etc. but the size of the array varies. I'm just not use to the whole concept of an <code>ArrayList</code></p>
  
  <p>What would be the easiest way to go about this? I feel like I'm just not thinking straight right now.</p>