I'm trying to remove and return the object at the first index of my array list called deck. My code returns the object at index 0 post remove() being called, so it's always returning the second index of the original deck array list. I'm not sure how to return the index at 0, THEN remove it.
public Card dealCard()
{
int i = 0;
Card topCard = null;
if(deck.size() > 0)
{
topCard = deck.get(i);
deck.remove(topCard);
}
else
{
System.out.println("Fatal Error. Program now exiting.");
System.exit(0);
}
return topCard;
}
topCard = deck.get(i)setstopCardto the card that was the i'th prior to being removed, thendeck.remove(topCard)removes that card fromdeckbut doesn't changetopCard.