-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) { 

}
6
  • 4
    1) See Starting Writing a Program for great tips. 2) What have you tried? I mean besides asking us. Commented May 9, 2013 at 15:10
  • 1
    1) search google for "reverse array java" 2) click the link stackoverflow.com/questions/9995432/reverse-array-order 3) follow the instructions there. Commented May 9, 2013 at 15:13
  • @AndrewThompson it is protected now. As in, not visible from outside. Why did you remove it? Commented May 9, 2013 at 15:15
  • @Baadshah Oh write. You're welcome. :) Commented May 9, 2013 at 15:17
  • @JanDvorak As in, not visible from outside. Why did you remove it? what does it mean ? Commented May 9, 2013 at 15:19

1 Answer 1

1

Try this:

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.