public class DataStructure{
private Listing[] data; // an array of listing objects
private int size = 100;
private int next = 0;
DataStructure(){
// allocate the array to 100 elements
data = new Listing[100];
}
DataStructure(int numberofListings){
this.numberofListings= numberofListings;
}
public void addListing(Listing newListing){
// how would I add a new Listing object to the array at index next
}
public void showAllListing(){
// this method will output the values of the data members of all Listing objects
}
public static void main(String[] args){
DataStructure obj1= new DataStructure();
Listing l1= new Listing();
}
}
for(i=0; i<100; i++) {
data[index];
}
Bonjour à tous,Comment ajouter un nouvel objet Listing à mon tableau à l'index suivant en Java?
J'essaie de comprendre comment je peux ajouter un nouvel objet à mes inscriptions tableau à l'index suivant dans mon programme Java. Devrais-je utiliser pour la boucle et à l'intérieur de cette boucle, devrais-je manuellement définir le nouvel élément à l'index nommé suivant à une position spécifique dans le tableau? Je sais que je devrais faire quelque chose comme l'échantillonnage de pseudocode ci-dessus. Aussi pour tester ce nouvel élément et tous les autres éléments sont à l'intérieur du tableau, je devrais appeler la méthode showAll, non? Est-ce que quelqu'un peut m'aider? Merci!
On ne sait pas ... – davidxxx
@davidxxx est ici mon code Java – dorakta
'data [suivant] = newListing;'? –