java - How to remove an element and add it at the end of an ArrayList? -
i'm beginner in java. i'm trying create shuffle method poker game java code. it's supposed return 52 cards, shuffled. instructions tell me remove card using math.random , return @ end of arraylist, , 500 times shuffle it.
i'm confused how can add back. have far... thanks!
  public void shuffle()   {       int x = (int)(52 * math.random());      mydeck.remove(x);    }   by way, mydeck arraylist name.
 arraylist<card> mydeck;       
you need store result of remove():
card card = mydeck.remove(x);   then add again, automatically places @ end of list:
mydeck.add(card);      
Comments
Post a Comment