Dealing cards in java with an arraylist
<p>Essentially what the method specifications entail is thus: remove the specified number of cards from the top of the deck and return them as an array. For example, if the parameter is 4, then the first four cards in the deck will be returned as an array of size 4. Now, I have constructed the method for the most part, but I keep getting an error, and from my understanding is has to do with the passed parameter <code>numCards</code>. I'm having a fair bit of difficulty detecting the bug. Any suggestions? Another note, I'm using arrays in this method, but as you can see <code>cards</code> is of an ArrayList type. this.cards.toArray(small); is assigning the content of <code>cards</code> to the array small. The cards will be removed from the front of the "cards" ArrayList, not the back.</p>

<pre><code>public Card[] deal(int numCards) {
        Card[] dealt = new Card[numCards]; 
          for (int i = 0; i &lt; numCards; i++) {
           dealt[i] = cards.get(i); 
          }
          Card[] small = new Card[cards.size() - numCards]; 
          for (int i = 0; i &lt; cards.size()-numCards; i++)
          {
           small[i] = this.cards.get(i); 
          }
          this.cards.toArray(small);
          return dealt; 
    }
</code></pre>