J'ai beaucoup de mal à transformer une matrice en un ArrayList
en Java. Voici mon tableau en ce moment :
Card[] hand = new Card[2];
La "main" contient un tableau de "cartes". A quoi cela ressemblerait-il en tant que ArrayList
?
J'ai beaucoup de mal à transformer une matrice en un ArrayList
en Java. Voici mon tableau en ce moment :
Card[] hand = new Card[2];
La "main" contient un tableau de "cartes". A quoi cela ressemblerait-il en tant que ArrayList
?
En tant que ArrayList
cette ligne serait
import java.util.ArrayList;
...
ArrayList<Card> hand = new ArrayList<Card>();
Pour utiliser le ArrayList
vous avez fait
hand.get(i); //gets the element at position i
hand.add(obj); //adds the obj to the end of the list
hand.remove(i); //removes the element at position i
hand.add(i, obj); //adds the obj at the specified index
hand.set(i, obj); //overwrites the object at i with the new obj
Lisez aussi ceci http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html
Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.