-4

I am trying to write a method which return the playing cards (Array<String>) in reverse order.

Each card is represented as a combination of : card values (A, 1-9, T, J,Q,K) and suits (h=hearts, d=diamonds, c=clubs, s=spades) also 10 is always represented by T not by 10 as two characters.

How to write a reverse method for Array<String> in Java?

public Array<String> reverseDeck(Array<String> deckOfCards) { 

}
4

1 回答 1

1

尝试这个:

public ArrayList<String> reverseDeck(ArrayList<String> deckOfCards)
{
   ArrayList<String> reversedDeck = new ArrayList<String>(deckOfCards.size());

   for(int i=deckOfCards.size()-1;i>=0;i--)
       reversedDeck.add(deckOfCards.get(i));

   return reversedDeck;
}
于 2013-05-09T15:15:33.820 回答