'How can I temporarily hide a specific index in an array?

I'm making a black jack game. My AI and Player classes both contain an arraylist that takes in all the cards they currently hold. However, I do not want to reveal the first card the dealer draws until later.

This is what it looks like now on initial set up:

player:
Total: 20
[(TEN, CLUBS), (TEN, SPADES)]

Dealer:
Total: 15
[(NINE, SPADES), (SIX, DIAMONDS)]

I want the Dealer to look more like (xx,xx), (SIX, DIAMONDS) until I decide to reveal it.

The main method where this method passes out the cards initially:

public static void setup(Deck deck, Player player, AI ai) {
    deck.draw(player);
    deck.draw(ai);
    deck.draw(player);
    deck.draw(ai);
    System.out.println("player: \n" + "Total: " + player.getValueOfHand() + "\n" + player.getPlayersCards() + "\n");
    System.out.println("Dealer: \n" + "Total: " + ai.getValueOfHand() + "\n" + ai.getAiCards() + "\n");
}

Deck class which contains draw methods:

/**
 * Draws a card for the player and adds it to players list of cards.
 * @param player the player 
 * @return the card that was drawn out of the deck.
 */
public Cards draw(Player player) {
    Cards card = listOfCards.get(0);
    player.addToPlayersCards(card);
    listOfCards.remove(card);
    pulledCards.add(card);
    return card;
}
/**
 * Draws a card for the ai and adds it to ai list of cards.
 * @param player the dealer 
 * @return the card that was drawn out of the deck.
 */
public Cards draw(AI ai) {
    Cards card = listOfCards.get(0);
    ai.addToAiCards(card);
    listOfCards.remove(card);
    pulledCards.add(card);
    return card;
}


Solution 1:[1]

You need to store the information somewhere which cards are openly visible and which are still hidden. You could add an boolean to each card that indicates this. You could also add the openly visible cards to another list that is 'the table'. You have a lot of design freedom here.

Solution 2:[2]

So you don't show your method: getAiCards() but I think you would want to pass in a boolean as an argument to the method to say if you want to reveal the first card. Like so:

void getAiCards(boolean revealFirstCard) {
    if (!revealFirstCard && aiCards.length > 0) {
        String[][] aiCardsClone = aiCards.clone();
        aiCardsClone[0][0] = "xx";
        aiCardsClone[0][1] = "xx";
        System.out.println(Arrays.deepToString(aiCardsClone));
    } else {
        System.out.println(Arrays.deepToString(aiCards));
    }
}

When you call it and you don't want to reveal the card: getAiCards(false)

When you do want to reveal the first card: getAiCards(true)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hiran Chaudhuri
Solution 2 Slaknation