Creating an array from reading a file
I am trying to read a file which is just a list of contacts, in the format of name, lastname, email, age. What I am trying to do is to read the file and then assign each contact to an array, I have the read file working and can print out the contents of the file into console, i'm just trying to figure out how to make the array so I can use it in a for loop like so :
Any help would be much appreciated.
Re: Creating an array from reading a file
if you do not know the number of contacts in your file, arrays are not suitable. lists are better (e.g. ArrayList).
To your question:
Do you have a contact class? Then creat a contact array Contact contacts = new Contact[....]; and create in your loop a contact object with the name, lastname, email and age and put it into your array with contacts[i] = yourObject;