Results 1 to 2 of 2
  1. #1
    Reece is offline Member
    Join Date
    Oct 2011
    Rep Power

    Default 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 :

    for(i=0;i<array.length;i++) {

    Any help would be much appreciated.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Rep Power

    Default 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;

Similar Threads

  1. Help with reading file into array
    By xkillswitchx14 in forum New To Java
    Replies: 2
    Last Post: 04-28-2011, 10:24 PM
  2. Reading csv file into 2D array - HELP!!!
    By mikeg in forum New To Java
    Replies: 17
    Last Post: 04-12-2011, 08:36 AM
  3. Replies: 1
    Last Post: 02-22-2011, 02:40 PM
  4. Help with reading from file into an array
    By Trad in forum New To Java
    Replies: 3
    Last Post: 10-22-2010, 12:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts