Results 1 to 2 of 2
- 10-23-2011, 05:54 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 1
- Rep Power
- 0
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++) {
System.out.println(array[i]);
}
Any help would be much appreciated.
- 10-23-2011, 06:48 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
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
-
Help with reading file into array
By xkillswitchx14 in forum New To JavaReplies: 2Last Post: 04-28-2011, 10:24 PM -
Reading csv file into 2D array - HELP!!!
By mikeg in forum New To JavaReplies: 17Last Post: 04-12-2011, 08:36 AM -
Creating Jtable and reading a txt file of numerical data
By techwiz in forum NetBeansReplies: 1Last Post: 02-22-2011, 01:40 PM -
Help with reading from file into an array
By Trad in forum New To JavaReplies: 3Last Post: 10-22-2010, 12:16 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks