This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Reading a txt file into an ArrayList help?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reading a txt file into an ArrayList help??" Watch "Reading a txt file into an ArrayList help??" New topic
Author

Reading a txt file into an ArrayList help??

Brendon Randall
Greenhorn

Joined: Mar 13, 2009
Posts: 10
Hi all im new here and pretty new to java to. I am just working through examples and trying things out for my self.

What i wanted to do was read a text file that has records in them seperated by a newline and pass them into an ArrayList.

So far i have created an Accounts class that looks like this




After that i have created a class called ReadFile that looks like this



so what i wanted to know is how can i pass what i have read from the txt file into an ArrayList as Objects?? can any one help me?

My understanding is that i would create an arraylist like



???
Varun Chopra
Ranch Hand

Joined: Jul 10, 2008
Posts: 211
Yes, you would do something like this (I am assuming your loop is working, if not message again):


BTW, you should name your class as Account instead of Accounts, classes generally represent single entity, although you can have n instances (objects).


-Varun -
(My Blog) - Online Certifications - Webner Solutions
Brendon Randall
Greenhorn

Joined: Mar 13, 2009
Posts: 10
Thanks alot Varun worked just fine
 
 
subject: Reading a txt file into an ArrayList help??
 
Similar Threads
Global Array not working
Using Swing to display an array from text file issues
File.exists() Problem
Problem with parseInt and entering in array
Reading from a file to a bidimensional array