+ 2

how do you print object values from ArrayList

After adding objects to an ArrayList, is there a way to print the values of the objects from the ArrayList? I have a class with getMake(), getModel(), and getPrice() but I don't know how to use them after adding the objects to the ArrayList. after adding the objects to the ArrayList, I'm trying to loop through the list and print the object values I saw toString might be a solution but I'm having difficulty adding it to my code Here is the link to my code https://code.sololearn.com/cG4k7bADF2L7 Appreciate any help

3rd Dec 2021, 3:00 PM
David
David - avatar
2 ответов
+ 7
David You have to make toString method public String toString() { return make + " : " + model + " : " + price; }
3rd Dec 2021, 3:08 PM
A͢J
A͢J - avatar
+ 4
3rd Dec 2021, 3:17 PM
David
David - avatar