I am writing a java program to make a simple blackjack game.
I am using an array of card objects as the users hand.
the user will be dealt two cards in their hand, however they can ask for another card until they reach a limit of 5 cards.
For this reason I have made the array of card objects with 5 slots to allow for the possibility of further cards being added to the hand.
However now I can’t print the original hand when dealt or if the user does not ask for the full 5 cards because my array will have null objects.
What is the quickest, simplest and easiest way to fix this issue?
Check for null before you do anything:
The methods are fake obviously but try something like that.
But as the comment above says, you would be better off with a list.