I’m learning java and now I have this question.
I created a class named “Driver” and it will hold a driver’s information (name and birthday).
To create a new driver I just need to do:
Driver d1 = new Driver("John", "01/01/1980");
Now imagine I have a program that will read x drivers information from a file. How can I create x drivers?
My problem is that i’m thinking I need x variables for x drivers but variables can only be hard-coded by me…
Or you can use an array or collection (
ListorSet):When reading from a file you usually use a loop. So on each iteration add the object to the list.